Operating Systems and Systems Integration

Lab 2, 3 Linux Study Guide 2 Supplement

1 Exercise (1)

1. What command will determine the version number of your kernel?

Look at the list of commands on the last slide labelled “Basic commands (27)”; it’s one of those:

         • which
         • uname -a
         • hostname
         • date
         • date +%Y%m%d%H%M%S
         • df -k
         • du -sk dir pathname
         • who
         • whoami
         • su

2. How could you find the percentage of your root partition that is used?

It is also one of the commands listed above.

3. Use sudo to find files under the /etc directory that match the following criteria:

• Filename starting with ta

• Filename starting with ta and filesize smaller than 100 bytes

• Filename starting with a and file type is link

• Filename starting with a and file owner is “news”

Use the find command. Add the -ls option to print details of files found so that you can check whether your search worked properly or not. Read the manual page for find; discuss with your neighbour how to tackle each part of this.

2 Exercise (2) — 1

1. Find out the detailed file type (more than the 4 types) of following files:

   /bin/vi, /bin/view, /etc/passwd, /dev/fd0, /dev/hda, /dev/isdn1,
   /bin/,  /etc/rc.d/init.d/crond,  /boot/vmlinuz-2.4.18-14,
   /boot/initrd-2.4.18-14.img?

Hint: read about the file command: man file.

Lab 2, 3 Linux Study Guide 2 Supplement Operating Systems and Systems Integration

2

2. Create a subdirectory, named lab2 3, under your home directory. Copy the scripts student cp and at cron from the network directory at

/home/nfs/ossi-part-time/scripts to $HOME/lab2 3/:
$ cd
$ mkdir lab2_3
$ cp -a /home/nfs/ossi-part-time/scripts/student_cp lab2_3
# Now press the up-arrow key and edit the above command line so it
# looks like this:
$ cp -a /home/nfs/ossi-part-time/scripts/at_cron lab2_3

Run the script student cp. This script will copy all files (except /bin/, /dev/fd0,

/dev/hda, /dev/isdn1) in part a to directory $HOME/lab2 3.

3. after copying, how could you use one command to know the sum of filesizes of all

files in $HOME/lab2 3/?

Hint: See section 1 on the preceding page; it’s one of the commands listed there.

3 Exercise (2) — 2

1. $HOME/lab2 3/passwd is a file containing information of each user account with the following format:

Username:password:uid:gid:comment:home-dir:shell-type

2. How can you check for the existence of the usernames of the users “root”, “bin”, “daemon,” and find out what their their uid and home directory are?

Hint: you might consider using the commands grep and cut.

3. What command can easily find the total number of accounts in file $HOME/lab2 3/passwd?

Hint: what command can count lines?

4. Copy $HOME/lab2 3/passwd to $HOME/lab2 3/passwd.new and compare these 2

files

5. modify the first and second lines of file $HOME/lab2 3/passwd.new with any editor and compare these 2 files again.

6. How could you generate a new file $HOME/lab2 3/passwd 2 which contains only username, uid, home-dir fields, separated by a vertical bar “|”, for each account?

7. How could you generate another file $HOME/lab2 3/passwd 3 which is sorted by value of uid of file in part 5?

Lab 2, 3 Linux Study Guide 2 Supplement Operating Systems and Systems Integration

3

4 Exercise (3)

1. Archive all files in directory $HOME/lab2 3/ into a single file, named “tarfile.tar”, without compression.

2. How would you list what files are archived in “tarfile.tar”?

3. Create a directory $HOME/lab2 3/extract/ and extract all files in “tarfile.tar” into this new directory.

4. Compress all files in $HOME/lab2 3/extract/

5 Exercise (4)

1. What is done by the script at cron?

(a) create a new file $HOME/lab2 3/filesize if this file does not exist.

(b) Then append “Hello...\n” to this file.

2. Schedule script $HOME/lab2 3/at cron.ksh to run at one minute later once. What is the result?

3. Redo part 2, but schedule to run at 9:10 p.m. What is the value of the job id?

4. Schedule script $HOME/lab2 3/a cron.ksh to run every one minute and observe the result 2 minutes later.

5. Un-schedule what you did in part 4.