Sie sind auf Seite 1von 10

CS 497C - Quiz 3 - Name: ________________

Date: Friday, November 9 (in class)

Part 1: (48 points - 4 points for each problem)

(2) 1. Which one won't remove the file Wal*Mart?


(1) rm 'Wal*Mart'
(2) rm 'Wal\*Mart'
(3) rm Wal*Mart
(4) rm Wal\*Mart

(1) 2. Which one is not equivalent to wc < in > out?


(1) < out wc > in
(2) > out wc < in
(3) wc > out < in
(4) < in wc > out

(4) 3. Which command is used to break the output in two streams?


(1) tar
(2) tr
(3) tail
(4) tee

(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

(3) 5. How do you show lines 5 to 10 of the file {\tt foo}?


(1) tail +5 foo | head
(2) tail +10 foo | head -5
(3) head foo | tail +5
(4) head -5 foo | tail +10

(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

(4) 12. Which command can you use to schedule a job?


(1) cal
(2) schedule
(3) set
(4) at

Part 2: (52 points)

1. What are three standard files in UNIX and what are their default
source? (6 points)

Ans: 1) Standard input - The default source is the keyboard.


2) Standard output - The default destination is the terminal.
3) Standard error - The default destination is the terminal.

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.

3. What is command substitution? Give an example. (6 points)

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:

2233|charles harris |g.m. |sales |12/12/52| 90000


9876|bill johnson |director |production|03/12/50|130000
5678|robert dylan |d.g.m. |marketing |04/19/43| 85000
2365|john woodcock |director |personnel |05/11/47|120000

Each line contains emp-id, name, designation, department, date of


birth, and salary.

Write the command to sort the file on the salary. (3 points)


Write the command to find out the unique designations. (3 points)

Ans: 1) sort -t'|' -n +5 +0 shortlist


or sort -t'|' -n +5 -6 shortlist
or sort -t'|' -n +5 shortlist
2) cut -d'|' -f3 shortlist | sort -u

7. What are three distinct phases in the creation of a process? Explain


it. (6 points)

Ans: 1) Fork - A copy of the process that invokes it is created.


2) Exec - The parent then overwrites the copy to create the child.
3) Wait - The parent waits for the death of the child.

8. What is a signal? What happens to a process when it receive a signal?


(6 points)

Ans: 1) A signal is an interrupt generated by the shell or even another


process in response to some error condition.
2) When a process receives a signal, it has to do one of three
things: (i) Do nothing. (ii) Ignore the signal. (iii) Trap the
signal.

9. What can you do with the job control facilities? (6 points)

Ans: 1) Put a job to the background (bg).


2) Bring it back to the foreground (fg).
3) List the active jobs (jobs).
4) Suspend a foreground job ([Ctrl-z]).
5) Kill a job (kill).

CS 497C - Quiz 2 - Name: ________________

Date: Monday, October 8 (in class)

Part 1: (20 points - 4 points for each problem)

(3) 1. How do you yank 5 lines in vi?


(1) 5xx (2) 5yw (3) 5yy (4) 5xx
(1) 2. Which command will tell you what directory you are currently in?
(1) pwd (2) cd (3) mkdir (4) whatdir
(4) 3. What character cannot be used when making a file name?
(1) = (2) | (3) \_ (4) /
(2) 4. What is equivalent to chmod u=rw,go=r file?
(1) chmod 600 file (2) chmod 644 file
(3) chmod 755 file (4) chmod 640 file
(2) 5. How would you display all files including hidden ones in columns
and identify directories and executables?
(1) ls -u (2) ls -Fax (3) ls -r (4) ls -R

Part 2: (30 points - 6 points for each problem)

1. How do you search forward for the string UNIX in vi?


How do you repeat this search in the same direction?
How do you repeat this search in the opposite direction?

Ans: /UNIX searches forward for the string UNIX.


n repeats the search in the same direction.
N repeats the search in the opposite direction.

2. How does UNIX divide files into three categories?

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.

3. Discuss three ways of knowing your home directory.

Ans: (1) Use cd; pwd


(2) Use echo $HOME
(3) Locate it in the line pertaining to your username in /etc/passwd.
(4) Use finger username.

4. A file with -rwxr-xr-x has what permissions are assigned to it?

Ans: Owner: read, write, execute;


Group: read, execute;
Others: read, execute.

5. What is the typical structure of a find command? Give an example?

Ans: (1) find path_list selection_criteria action


(2) find . -name "*.c" -print

CS 497C - Quiz 1 - Name:_________________

Date: Wednesday, September 19 (in class)

Part 1: (48 points - 4 points for each problem)

(2) 1. The ls command displays the contents of the files in your


directory.
(1) true (2) false

(4) 2. The correct unix command to display the contents of a file is


(1) cat (2) more (3) less (4) all of the above

(3) 3. What is the correct command to end a script file?


(1) Ctrl-z (2) Ctrl-q (3) Ctrl-d (4) Ctrl-l
(1) 4. What is the command to suspend a job?
(1) Ctrl-z (2) Ctrl-q (3) Ctrl-d (4) Ctrl-l

(2) 5. Where is the password stored?


(1) /etc/passwd (2) /etc/shadow (3) /etc/group

(3) 6. Which one shows the name of the operating system?


(1) uname -n (2) uname -r (3) uname (4) uname -m

(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

(2) 8. Which command is used to count lines, words, and characters in


a file?
(1) bc (2) wc (3) cp (4) mv

(4) 9. Which command is used to check your current directory?


(1) dd (2) cd (3) ld (4) pwd

(3) 10. How do you abort an editing session in vi?


(1) :e! (2) :w! (3) :q! (4) :z!

(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.

Part 2: (52 points)

1. List three different operating systems. (6 points)

Ans: UNIX, Windows, Mac OS

2. List three commands that you can use to log out of the system.
(6 points)

Ans: Ctrl-d, logout, exit

3. Describe the functions of the kernel and the shell. (6 points)

Ans: The kernel interacts with the machine's hardware.


The shell interacts with the user.

4. How can you save the output of the who, date, and cal in a single
file? (5 points)

Ans: (who; date; cal) > filename

5. What is PATH? (6 points)

Ans: PATH is a system variable which stores a lists of directories


that the shell searches to locate a command.
6. Write the command to display the current date in the form dd/mm/yyyy.
(5 points)

Ans: Use date +%d/%m/%Y, date +"%d/%m/%Y", date +/%d/%m/20%y, or


date +"/%d/%m/20%y".

7. How do you use bc to find out the hexadecimal equivalent of a


binary number 1101001? (6 points)

Ans: ibase = 2
obase = 16
1101001

8. Name three ways of quitting vi in addition to saving the file. (6


points)

Ans: Use the command :x, :wq, or ZZ to save and quit the editor.

9. Summarize the three modes in which vi works. (6 points)

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.

CS 497C - Quiz 4A - Name: ______________

Date: Friday, December 7 (in class)

Part 1: (20 points - 4 points for each problem)

(2) 1. Which command reveals details of users?


(1) w (2) finger (3) who (4) detail

(2) 2. When using ftp, how do you list files in your local directory?
(1) lls (2) !ls (3) lcd (4) !cd

(4) 3. If a script is run as foo -l -t bar[1-4], what is the value of $#?


(1) 3 (2) 4 (3) 5 (4) 6

(1) 4. Which one is the here document?


(1) << (2) >> (3) <1 (4) >1

(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

Part 2: (30 points - 6 points for each problem)


1. What is a domain name? Give an example of a domain name.
2. Ans: 1) A domain name locates an organization or other entity on the
Internet.
3. 2) www.cs.twsu.edu is a domain name.
4. What is a port number for?
In which file are known port numbers specified?
Give an example.
5. Ans: 1) A port number is a number which is used to identify a TCP/IP
service.
6. Daemons listen for requests at certain specific port numbers
assigned
7. to them.
8. 2) Know port numbers are defined in /etc/services.
9. 3) sendmail listens on port 25, ftp on 21 and telnet on 23.
10. How do you upload and download files in ftp?
How do you set the transfer mode for a text file and an image file in ftp?
11. Ans: 1) Use put or mput to upload. Use get or mget to download.
12. 2) Set ascii mode to transfer a text file and set binary mode to
13. transfer an image file.
14. What will this statement do?
filename=${1:-emp.lst}
15. Ans: If a script is invoked without any argument, $1 would be null and
16. filename would be set to emp.lst.
17. Write a script to read in a number n as an argument and calculate the arithmetic
summation 1 + 2 + 3 + 4 + .... + n.
18. Ans: #!/bin/sh
19. n=$1
20. sum=$1
21. while [ $n -gt 1 ]
22. do
23. n=`expr $n - 1`
24. sum=`expr $sum + $n`
done
CS 497C - Mid-Term Exam - Name: ____________
Date: Friday, October 19 (in class)

Part 1: (44 points - 4 points for each problem)

(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

(3) 2. What command is generally used to end an input session?


(1) Ctrl-z (2) Ctrl-q (3) Ctrl-d (4) Ctrl-l

(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 .

Part 2: (56 points)

1. What is an operating system? List three different operating systems.


(6 points)

Ans: (1) An operating system (sometimes abbreviated as "OS") is a program


that functions as a virtual machine (layer of software on top of
bare hardware) and a resource manager (software that controls
access to computer).
(2) DOS, Windows, Mac OS, and UNIX.

2. What is PATH? How do you evaluate its value? (6 points)

Ans: (1) PATH is a system variable which stores a lists of directories


that the shell searches to locate a command.
(2) Use echo $PATH to evaluate its value.
3. Name three ways of quitting vi and saving the file. (6 points)

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: Mark the beginning of the region by [Ctrl-Spacebar] or [Ctrl-@] and


move the cursor to the end of the region. Copy it by [Alt-w]. Put it
by [Ctrl-y].

5. How does UNIX divide files into three categories? (6 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.

6. What directories do . (a single dot) and .. (two dots) represent


respectively? (4 points)

Ans: . (a single dot) represents the current directory.


.. (two dots) represents the parent directory.

7. If mkdir foo doesn't create the directory, what could be the possible
reasons? Write at least three possible reasons. (6 points)

Ans: (1) The directory foo already exists.


(2) An ordinary file with the same name exists.
(3) The user doesn't have permission to create it.

8. A file with {\tt -rwxr-x--x} has what permissions assigned to it?


(6 points)

Ans: Owner: read, write, execute;


Group: read, execute;
Others: execute.

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)

Ans: find . -name "*.html" -exec mv {} ../htdocs \;


Q: Print all lines containing the string San.
A: grep 'San' Databook
1
2 Q: Print all lines where the person's first name starts with J.
3 A: grep '^J' Databook
4
5 Q: Print all lines ending in 700.
6 A: grep '700$' Databook
7
8 Q: Print all lines that don't contain 834.
9 A: grep -v -e '834' Databook
10
11 Q: Print all lines where birthdays are in December.
12 A: grep -E ':[0-9]+\/12\/[0-9]+' Databook
13
14 Q: Print all lines where the phone number is in the 408 area code.
15 A: grep -E ':408-[0-9]{3}-[0-9]{4}:' Databook
16
17 Q: Print all lines containing an uppercase letter, followed by four
18 lowercase letters, a comma, a space, and one uppercase letter.
19 A: grep '[A-Z][a-z]\{4\}, [A-Z]' Databook
20
21 Q: Print lines where the last name begins with K or k.
22 A: grep -E '\<.*\>[\t ]\<(K|k)' Databook
23
24 Q: Print lines preceded by a line number where the salary is a six-figure
25 number.
26 A: grep '[0-9]\{6\}$' Databook
27
28 Q: Print lines containing Lincoln or lincoln (remember that grep is
29 insensitive to case).
30 A: grep '[Ll]incoln' Databook
or grep -E '(L|l)incoln' Databook