CPE3007 System Development using UNIX

Week Two Tutorial Exercises

1. What is the effect of the following command sequences?

a) ls | wc -l
b) who | wc -l
c) ls *.c | wc -l
d) who | sort
e) rm ???
f) rm *.o
g) cd; pwd
h) plotdata 2>errors &
i) who | wc -l > number (Kochan and Wood P 40)
2. a) Use the cat command to create a file file1 containing the text Line 1
Line 2
        by redirecting its output

    b) Use the cat command to display the contents of file1 by redirecting input.
    c) Use the cat command and redirection to append the text

Line 3
Line 4
        to the end of file1and confirm that this has been done.

3. a) Create a file called days that contain the days of the week, one per line.
    b) Use a pipe to display a sorted list of the days to the screen.
    c) Repeat b) but direct the output to a file called days_sort.

4. a) Using the file days determine the access mode set on the file.
    b) Using the chmod who [...][...] file format, set the access permission to allow yourself all access,
        members of your group no access and others read and write access.
        Confirm your change.
    c) Set the permission for members of your group to read and write access and all others no access.
        Confirm your change.

5. Given the following files in your current directory:

$ ls
feb90
jan12.91
jan19.91
jan26.92
jan5.93
jun87
jun88
jun89
jul89
jul93
mar93
memo1
memo10
memo2
memo.dat
$
    What would be the output from the following commands? a) echo * b) echo m[a-df-z]*
c) echo jan* d) echo ?????
e) echo [jm][au][nr]* f) echo *[!0-9]
g) echo [A-Z]* h) echo *.* (Kochan and Wood P40)
6. Which of the following are valid variable names? XxXxXx
12345
file.name
file_name
file1
_
HOMEDIR
_date
x0-9
Slimit (Kochan and Wood P115)  
7. Suppose your HOME directory is /usr/person and that you have subdirectories as shown below:

Assume you have just logged into the system and typed the following commands:

$ docs=/usr/person/documents
$ let=$docs/letters
$ prop=$docs/proposals
$ prog=/usr/person/programs
    Write the commands in terms of these variables to: a) List the contents of the documents directory
b) Copy all files from the letters directory to the proposals directory.
c) Move all files whose names contain a capital letter from the letters directory to the current directory.
d) Count the number of files in the memos directory.
    What would be the effect of the following commands? a) ls $let/..
b) cat $prop/sys.A >> $let/ask.ALP
c) echo $let/*
d) cp $let/ask.ALP $prog
e) cd $prop                                                                                                   (Kochan and Wood P115 - 116)  
8. Write a program called numfile to display the number of files in your current directory.