



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Summer 2009
Name__________________ Date_____________________
1. What is a pipe in UNIX? Give an example to explain it. (8 pts).
A pipe allows a user to specify that the output of one process is to be used as the input of
another process. Two or more processes may be connected in this fashion, resulting in a
“pipeline” of data flowing from the first process through to the last.
Example: who|sort. The utility who outputs an unsorted list of the users and the utility
sort will output a sorted version of its input. They are connected together with a pipe so
that the output from who passes directly into sort, resulting in a sorted list of users.
2. What are the absolute pathname and the relative pathname? Assume we have the
UNIX directory hierarchy that contains four files F1-F4 as shown in Figure 1, and
the current directory is csc3320****. (22 pts)
(a) Please give the absolute pathname and the relative pathname for these four files.
(8 pts)
Absolute pathnames:
/home/F
/ (root)
home bin
csc
F3 tests
Figure 1
/bin/F
/home/csc3320/F
/home/csc3320/tests/F
Relative pathnames:
../../bin/F
./tests/F
(b) If the file F4 has the permissions of u-rwx, g-r, o-rx, write the command to
change the permission setting to 657 using two different approaches. (4 pts)
chmod - R 657 ./tests/F
chmod –R u-x, g+x, o+x ./tests/F
(c) Write down utilities or commands for the following actions. (10pts)
ls –al ../../bin
more ../F
mkdir ./tests/solutions
cp ./tests/F4 ../ or cp ./test/F4 /home
rm –ir ../csc
(b) Use search and replace command in vi editor to complete the change below. (
pts)
f(x,y,t)
f(2,s(t),z(t))
f(m+n,m-n,5)
f(t y x)
f(z(t) s(t) 2)
f(5 m-n m+n)
:1,3s/f(([^,]),([^,]),(.*))/f(\3 \2 \1)/g
(c) Assume the original texts in vi editor are shown as below. Write down the texts
after executing the following command. (6 pt)
csc
csc
csc
:1,3s/(.*)/ls –alg /home/fgu/\1/g
/home/fgu/csc
/home/fgu/csc
/home/fgu/csc
(d) Use grep/egrep to do the following search in the file exam1. (6 pt)
(1) Display lines which include at most two successive ‘a’.
egrep – v “aaaa*” exam1 or
egrep – v “aaa+” exam1 or
egrep “[^a]|[^a][a][^a]|[^a]aa[^a]”
(2) Display lines which start with an uppercase letter or end with a number.
egrep “^[A-Z]|[0-9]$”
5. Answer the following questions. (12 pts, 4 pts each)
(1) Describe the differences between cmp and diff , and construct an example to explain
them.
cmp compares two files for equality, and reports the first byte where there is a mismatch.
diff compares two files and outputs a description of their difference.
(2) Write a command to find all .java files in the current directory, list and copy them to
the folder program.
find. –name ‘*.java’ –ls –exec cp {} .\program;
(3) Describe the differences between hard links and soft links.
Hard links are restricted to one file system, and soft links can be created from one file
system into another file system.
7. Utilize sed to do the following queries. (10 pts)
(1) Change Computer Science to CS in the file departments.
sed ‘s/Computer Science/CS/g’ departments
(2) Add two lines of “colleges” and “department” in the beginning and remove last two
lines of the file departments (totally 10 lines).
cat > sed
1i\
colleges\
department
9,10c\
sed – f sed1 departments
(3) Insert the file colleges after at the end of the file departments.
Sed ‘$ r colleges’ departments