(3) 4. You want to concatenate two files, a and b, but also insert some text
in between from the terminal. How will you do this?
(1) cat - a b > c
(2) cat - a b > c
(3) cat a - b > c
(4) cat a b - > c
(1) 6. How will you find out the lines common to two sorted files?
(1) comm -12 foo1 foo2
(2) cmp -12 foo1 foo2
(3) comm -23 foo1 foo2
(4) cmp -23 foo1 foo2
(2) 7. How do you know how many different users are logging into the system?
(1) who | uniq | sort | wc -l
(2) who | cut -d' ' | uniq | wc -l
(3) who | sort | uniq | wc -l
(4) who | cut -d' ' | uniq -d | wc -l
(2) 8. How do you remove duplicate lines from the file foo using sort?
(1) sort -d foo
(2) sort -u foo
(3) sort -n foo
(4) sort -p foo
(1) 9. Which system variable is used to store the PID of the current shell?
(1) $$
(2) $!
(3) $%
(4) %$
(4) 10. How do you find out the complete command line of a process run by
user romeo?
(1) ps -a -u romeo
(2) ps -d -u romeo
(3) ps -e -u romeo
(4) ps -f -u romeo
(3) 11. Which one will you use to make sure that a process is killed?
(1) kill -7
(2) kill -8
(3) kill -9
(4) kill -10
1. What are three standard files in UNIX and what are their default
source? (6 points)
2. What is a filter? Where does a filter get its input from? (6 points)
Ans: 1) A filter is a command which uses both standard input and standard
output.
2) It can accept input from (i) a file with < (ii) a pipeline using |.
Most filters accpet input from the keyboard as well.
Ans: 1) The shell executes the command enclosed within a pair of back quotes
(``) and places the command text where it occurs with the output the
command generates.
2) echo Today is `date`.
4. Sort the file {\tt /etc/passwd} on GUID (primary) and UID (secondary)
so that the users with same GUID are placed together. Users with a
lower UID should be placed higher in the list. (5 points)
Ans: You require to do a numeric sort on the fourth and third fields:
sort -t: -n +3 +0 +2 /etc/passwd
or sort -t: -n +3 -4 +2 /etc/passwd
or sort -t: -n +3 -4 +2 -3 /etc/passwd
5. How will you find out the number of times the character ? occurs in
a file? (5 points)
Ans: Delete all characters except the ? and then make a character count with
wc: tr -cd '?' < foo | wc -c
6. Consider the following text file shortlist:
Ans: Ordinary file - Also known as regular file. It contains only data
as a stream of characters.
Directory file - A folder containing the names of other files and
directories.
Device file - It represents all hardware devices.
(2) 7. If you don't have the apropos command on your system, which
command can you use?
(1) man -l (2) man -k (3) man -f (4) man -c
(4) 11. Your screen shows junk in vi. How do you clear it?
(1) Ctrl-z (2) Ctrl-q (3) Ctrl-d (4) Ctrl-l
(1) 12. How do you delete text from the current line to the beginning
of the file in vi?
(1) d1G (2) 10dd (3) d$ (4) df.
2. List three commands that you can use to log out of the system.
(6 points)
4. How can you save the output of the who, date, and cal in a single
file? (5 points)
Ans: ibase = 2
obase = 16
1101001
Ans: Use the command :x, :wq, or ZZ to save and quit the editor.
Ans: Command mode - where keys are used as commands to act on text.
Input mode - where any key depressed is entered as text.
Last Line mode or ex mode - where commands can be entered in the last
line of the screen to act on text.
(2) 2. When using ftp, how do you list files in your local directory?
(1) lls (2) !ls (3) lcd (4) !cd
(3) 5. To debug shell script, what is put into the beginning of the script?
(1) set -dg (2) set -u (3) set -x (4) set -w
(2) 1. Which part of the operating system gets loaded into memory as soon
as the system is booted?
(1) shell (2) kernel (3) file (4) process
(2) 3. If the {\bf apropos} command is not available, which command can
you use?
(1) man -l (2) man -k (3) man -f (4) man -c
(4) 4. How do you delete text from the current line to the beginning of
the file in vi?
(1) 1GdG (2) dG (3) d0G (4) d1G
(1) 5. How do you globally replace Internet with Web occurring in all
lines using vi?
(1) :1,\$s/Internet/Web/g (2) :1,\$s/Internet/Web
(3) :.,\$s/Internet/Web/g (4) :.,\$s/Internet/Web
(1) 6. How can you quit emacs?
(1) [Ctrl-x][Ctrl-c] (2) [Ctrl-x][Ctrl-f]
(3) [Ctrl-x][Ctrl-q] (4) [Ctrl-x][Ctrl-s]
(3) 7. What command is used to interactively delete files?
(1) rm (2) rm -d (3) rm -i (4) rm -a
(3) 8. What command is used to rename a file?
(1) ren (2) rename (3) mv (4) newname
(2) 9. How would you display all files including hidden ones in columns
and identify directories and executables?
(1) ls -lat (2) ls -Fax (3) ls -tar (4) ls -Rak
(3) 10. What is equivalent to chmod 711 file?
(1) chmod u=rw,go=x file (2) chmod u=rw,go=rx file
(3) chmod u=rwx,go=x file (4) chmod u=rwx,go=rx file
(4) 11. How do you symbolically link /usr/games/netris with a file of
the same name in your current directory?
(1) ln . /usr/games/netris (2) ln /usr/games/netris .
(3) ln -s . /usr/games/netris (4) ln -s /usr/games/netris .
Ans: Use the command :x, :wq, or ZZ to save and quit the vi editor.
4. How do you mark a region, copy it, and put it in the new location
in emacs? (5 points)
Ans: Ordinary file - Also known as regular file. It contains only data as
a stream of characters.
Directory file - A folder containing the names of other files and
directories.
Device file - It represents all hardware devices.
7. If mkdir foo doesn't create the directory, what could be the possible
reasons? Write at least three possible reasons. (6 points)
9. Specify which file attributes change when you copy a file from another
user account. (6 points)
Ans: (1) The file's owner changes to the user who copys this file.
(2) Last modification and access time changes to the time of copy.
(3) If the two users are in different groups, the file's group
changes.
(4) File permissions change to the default permission of the user
who copy this file.
10. Use the {\tt find} command to move all files with the html extension
(i.e. {\tt *.html}) from the current directory to the htdocs directory
under the parent directory.
hint: This can be done with the -exec operator, followed by the command
to be executed and terminated with the sequence {} \; (5 points)