Sie sind auf Seite 1von 11

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 - (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 chec 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 jun 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 ernel and the shell. (6 points)

Ans: The ernel 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 wor s. (6 points) Ans: Command mode - where eys are used as commands to act on text. Input mode - where any ey 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. Choice Questions: Chapter 4 (3) 1. How do you yan 5 lines in vi? (V) (1)5xx (2)5yw (3)5yy (4)5xx (4) 2. Which command replaces a single character with another in vi? (III) (1) a (2) J (3) i (4) r (2) 3. What eyboard shortcut can you use in vi, as well as many other programs, to redraw the screen? (II) (1) Ctrl-d (2) Ctrl-l (3) Ctrl-e (4) Ctrl-s (1) 4. How do you move your cursor to line 40 in vi. (II) (1) 40G (2)40L (3)G40 (4) 40R Chapter 6 (1) 5. Which command will tell you what directory you are currently in? (VIII) (1) pwd (2) cd (3) m dir (4)whatdir (3) 6. How long can a UNIX filename be on modern systerm? (VIII) (1) 4 (2) 16 (3) 255 (4) 128

(4) 7. What command is used to create a directory? (VII) (1) rmdir (2) cd (3) dir (4) m dir (1) 8. What command is used to remove a directory? (V) (1) rmdir (2) cd (3) dir (4) m dir (2) 9. What command is used to copy files and directories? (IV) (1) copy (2) cp (3) rn (4) cpy (1) 10. What character cannot be used when ma ing a file name? (IV) (1) / (2) | (3) _ (4) = (3) 11. What is the command to interactively delete files? (IV) (1) rm (2) rm -d (3) rm -i (4) rm -a (3) 12. Which command is used to rename a file? (IV) (1) ren (2) rn (3) mv (4) mvdir Chapter 7 (1) 13. What command is used for changing file permissions? (VI) (1) chmod (2) cdmod (3) rdmod (4) dmod (1) 14. How do you show all files (hidden and dot files) in a directory? (V) (1) ls -a (2) ls -x (3) ls (4) ls -t (2) 15. What command is used to show a long listing of file attributes? (IV) (1) ls -a (2) ls -l (3) ls -x (4) ls -t (3) 16. The permission -rwxr--r-- represents in octal expression is (IV) (1)777 (2)666 (3)744 (4)711 (3) 17. Which command is used to assign read-write permission to the owner? (IV) (1) chmod a+r file (2) chmod o+r file (3) chmod u=rw file (4) chmod og-r file (4) 18. Which of the following commands is used to transfer the ownership of a file? (III) (1) trown (2) chmod (3) umas (4) chown (2) 19. How would you display all files including hidden ones in columns and identify directories and executables? (III) (1) ls -u (2) ls -Fax (3) ls -r (4) ls -R (1) 20. How can you add the write permission to the group and the read permission to the others? (II) (1) chmod g+w, o+r file (2) chmod a+r, g+x file (3) chmod g+x, o+r file (4) chmod u+x, g+r file Question & Answer: Chapter 4 1. How do you search forward for the string UNIX in vi? (IV) 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 do you recover a file from a crash in vi? (III) Ans: vi -r filename 3. What is the Command Mode in vi? (III) Ans: The Command Mode is where eys are used as commands to act on text. 4. How do you globally replace Internet with Web occurring in all lines using vi? (II) Ans: Use :1,$s/Internet/Web/g Chapter 6 5. How UNIX divides files into three catrgories? (VIII) Ans: Ordinary file - Also nown 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 is the difference between relative and absolute pathnames? (VII) Ans: A relative pathname uses the current direcotry as point of reference and specifies the path relative to it. An absolute pathname uses the root as the reference for the file. All paths originate from the root. 7. List three commands that are used to compress files. (V) Ans: gzip, zip, compress 8. What does rm -r * do? (IV) Ans: It is used to delete all files in the current directory and all subdirectories and their files. 9. How do the df and du commands differ? (IV) Ans: The df command tells you about the partitions, total space and space available in each partition, mount points. The du command shows dis usage i.e. you can chec the dis space used by a specific drirectory or directories. 10. What directories do . (a single dot) and .. (two dots) represent respectively? (III) Ans: . (a single dot) represents the current directory. .. (two dots) represents the parent directory. 11. What does the cd command do when used without arguments? What does cd .. do? (III) Ans: When the cd command is used without arguments, it returns the

user to the home directory. cd .. will change the user to the parent directory. 12. What are two functions of the mv command? (II) Ans: Rename a file (or a directory). Move a group of files to a different directory. Chapter 7 13. A file with -rwxr-xr-x has what permissions assigned to it? (V) Ans: Owner: read, write, execute; Group: read, execute; Others: read, execute.

Ans: A file can have three sets of permissions which are: read, write, and executable. 15. What is the umas command and how can it be evaluated? (III) Ans: The umas commands refers to the user mas . The default permission setting is transformed by subtracting the user mas from it to remove one or more permissions. This mas evaluated by use the umas command. 16. List two ways to assign file permissions which indicate only the owner can read and write the file. (III) Ans: chmod 600 filename chmod u=rw filename 17. What is the typical structure of a find command? Give an example? (III) Ans: (1) find path_list selection_criteria action (2) find . -name "*.c" -print 18. What are the three time stamps associated with a file? (II) Ans: Time of last file modification, last access, and last inode modification 19. What are the three components contained in the chmod command? (II) Ans: Category of user (owner, group, others) Operation to be performed (assign or remove a permission) Permission type (read, write or execute) 20. What is a symbolic lin ? (II) Ans: A symbolic lin is a directory entry that points to the file or directory that actually has the contents. 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?

14. What are the three

inds of permission a file can have? (IV)

(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 brea 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 now 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 ma e sure that a process is illed? (1) ill -7 (2) ill -8 (3) ill -9 (4) ill -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 eyboard. 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 eyboard as well. 3. What is command substitution? Give an example. (6 points) Ans: 1) The shell executes the command enclosed within a pair of bac 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 ma e a character count with wc: tr -cd '?' < foo | wc -c 6. Consider the following text file shortlist: 2233|charles harris 9876|bill johnson 5678|robert dylan 2365|john woodcoc |g.m. |director |d.g.m. |director |sales |12/12/52| 90000 |production|03/12/50|130000 |mar eting |04/19/43| 85000 |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) or or 2) sort -t'|' -n sort -t'|' -n sort -t'|' -n cut -d'|' -f3 +5 +0 shortlist +5 -6 shortlist +5 shortlist shortlist | sort -u

7. What are three distinct phases in the creation of a process? Explain it. (6 points) Ans: 1) For - A copy of the process that invo es 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 bac ground (bg). 2) Bring it bac to the foreground (fg). 3) List the active jobs (jobs). 4) Suspend a foreground job ([Ctrl-z]). 5) Kill a job ( ill). 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) What is a domain name? Give an example of a domain name. Ans: 1) A domain name locates an organization or other entity on the Internet. 2) www.cs.twsu.edu is a domain name. What is a port number for? In which file are nown port numbers specified? Give an example. Ans: 1) A port number is a number which is used to identify a TCP/IP service. Daemons listen for requests at certain specific port numbers assigned to them. 2) Know port numbers are defined in /etc/services. 3) sendmail listens on port 25, ftp on 21 and telnet on 23. 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? Ans: 1) Use put or mput to upload. Use get or mget to download. 2) Set ascii mode to transfer a text file and set binary mode to transfer an image file. What will this statement do? filename=${1:-emp.lst} Ans: If a script is invo ed without any argument, $1 would be null and filename would be set to emp.lst. Write a script to read in a number n as an argument and calculate the arithmetic summation 1 + 2 + 3 + 4 + .... + n. Ans: #!/bin/sh n=$1 sum=$1 while [ $n -gt 1 ] do n=`expr $n - 1` sum=`expr $sum + $n` done echo "Sum = $sum." CS 497C - Quiz 4B - Name: ______________ Date: Friday, December 7 (in class) Part 1: (20 points - 4 points for each problem) (2) 1. When you loo for a pattern in files ignoring case which one will you use? (1) grep -v (2) grep -i (3) grep -l (4) grep -e (4) 2. Which command has the same result as head -3? (1) tail +3 (2) sed '3d' (3) sed '3p' (4) sed '3q' (1) 3. If x has the value 10, what is the value of x$x$? (1) x10$ (2) 1010 (3) 10x$ (4) x$10 (1) 4. Which special parameter indicates the name of the script? (1) $0 (2) $1 (3) $! (4) $* (3) 5. What can be put into the first line of your script to ma e sure a script will use the Bourne shell? (1) #!/bin/csh (2) #/bin/sh (3) #!/bin/sh (4) $/bin/sh Part 2: (30 points - 6 points for each problem) What is an interval regular expression (IRE)? Give an example of IRE. Ans: 1) An IRE is an expression that uses the characters { and } with a single or pair of numbers between them. 2) ch\(m\) - Here, the metacharacter ch can occur m times. a\{5,10\} What is the sed command? Describe the format of the sed command. Give an example

. Ans: 1) sed is a multipurpose tool which combines the wor of several filters. 2) sed options 'address action' file(s) 3) sed -n '1,$s/Basic/Java/g' foo Frame regular expressions to match lines containing (i) jefferies jeffery jeffey s (ii) hitchen hitchin hitching (iii) dix dic s dic son dixon. Ans: (i) jeffe*r*[iy]e*s* (ii) hitch[ei]ng* (iii) di[xc] *s*o*n* sum and n are two variables with numeric values. Write a script to calculate sum / n with two digital precision after the decimal point. Ans: echo "scale=2; $sum / $n" | bc Write a script to read in a number n as an argument and calculate its factorial n! where n! = n x (n - 1) x (n - 2) x .... x 1. Ans: #!/bin/sh n=$1 fac=$1 while [ $n -gt 1 ] do n=`expr $n - 1` fac=`expr $fac \* $n` done echo "$1! = $fac." 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) ernel (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 - (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 -Ra (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 lin /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 mar a region, copy it, and put it in the new location in emacs? (5 points) Ans: Mar 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 nown 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 m dir 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 \;