Answer the following questions and write out the exact command(s) you used (100 points)
A. 25 points
2. List only the dot files in your homedirectory
and recursively list the directories starting with a dot.
ls -r .*
3. Use the command file with the option -f to display the types of the files in your home directory with a one line command.
ls > ff | file -f ff | cut -f2 -d ':' | sort | uniq
4. What is the PID of your login shell?
Explain in detail your choice of a number from the output of the command
ps.
$ ps aux | grep bash
The shell with the earliest start time info.
araja:~$ ps aux | grep bash
araja 8357 0.0
0.3 1.97M 384K ttyp2 S 09:22:31
0:00.30 bash
araja 8214 0.0
0.3 1.94M 392K ttyp1 I + 08:48:11
0:00.63 bash
In this case its 8214.
5. Create a file that contains the process numbers
associated with at least two jobs arranged in descending order.
example contents of output file:
2930
2928
jobs -l > o2 | cut -f3 -d ' ' o2 | sort -r
B. 75 points
1. Write a script which will write your username, your homedirectory, the type of terminal and the printer that lp uses, so that the output looks like
Your username is chris
Home directory is /cs/ugrad/chris
You are using a terminal which is a vt100
The default lineprinter is cs/p1.
cat >myscript
echo Your user name is $USER
echo Home directory is $HOME
echo You are using a terminal which is a $TERM
echo The default lineprinter is $PRINTER
Control-D
2. Write a script which finds the oldest file in your home directory and prints name and the size of file on the screen preceded by the message
The name and size of file are:
xyz 475
ls -lt | tail -n 1 | cut -c16-22,37-40
3. List names of files in your home directory which
4. Use the commands ps, kill, jobs,
fg, bg, grep
5. Redirections and commands cat,
wc, tail, head.
Extra Credit:
(15 points)
Explain in detail what the following 2 commands do
echo baz 2>"foo" >& 2
The word 'baz' will be printed in the file
foo. We are redirecting STDERR to foo and then redirecting STDOUT TO STDERR.
So all output goes to foo.
echo baz >&2 2> "foo"
Here the order
is important. We are first redirecting STDOUT to STDERR and then changing
STDERR to foo. The word baz will be printed on the screen and not in file
foo.