Unix Term Test #2 DAT2330 - Ian Allen - Fall 2003-1- 100 minutes Evaluation: 70 Questions Name: _________________________ Important Instructions 1. Read all the instructions and both sides of all pages. 2. Manage your time when answering questions on this test. Answer the questions you know, first. _________________________________________________________________ Multiple Choice - 70 Questions - 20% of 30% (Office use only: 51 44 27 66 8 26 62 35 7 10 39 49 19 57 63 16 50 24 13 12 33 34 37 55 2 21 67 15 46 14 28 42 41 6 23 56 69 38 64 3 36 11 60 48 25 31 32 5 22 18 65 17 53 29 43 45 20 30 52 40 58 47 59 1 61 70 4 68 9 54) 1. If the file pig contained the word foo, what would be the bash shell output of this two command sequence: PATH=/etc/passwd:/bin/ls:/bin/cat ; /bin/ls pig a. /bin/ls: pig: No such file or directory b. bash: /bin/ls: command not found c. no output d. pig e. foo 2. What is the output of this command sequence: echo pig >one ; echo cow | head -2 one a. pig followed by cow b. an error message c. pig d. cow followed by pig e. cow 3. What is the bash shell output of this command sequence: true && echo Hello There $? a. Hello There ? b. no output c. Hello There 0 d. Hello There 1 e. Hello There ? 4. What is the output of this sequence of three shell commands: echo x >abc ; ls >abc abc ; wc abc a. 1 1 2 abc b. 0 0 0 abc c. 1 1 3 abc d. no output e. 1 1 4 abc 5. What is the output of the following sequence of bash commands: date='October Monday' ; test date = date a. 0 b. Mon Oct 27 17:01:38 EST 2003 c. 1 d. test: too many arguments e. no output 70 Questions DAT2330 Unix Final - 30% 100 minutes DAT2330 - Ian Allen - Fall 2003-2- 100 minutes 6. Which bash command sequence below always outputs just the date only if the first argument is both not empty and a directory? a. if [ "-s $1" && "-d $1" ]; then date ; fi b. if [ "$1" -eq -f -a "$1" -eq -d ]; then date ; fi c. if [ -d "$1" -a -s "$1" ]; then date ; fi d. if [ -s && -d "$1" ]; then date ; fi e. if [ -s -a -d "$1" ]; then date ; fi 7. If happy were a file of text containing 50 different lines, what would be the output of this exact command line: diff happy happy a. an error message because diff doesn't allow the same file name twice b. no output c. an error message because diff only allows one file name d. several lines, which are the lines that are different between the two files e. the contents of file happy would be displayed 8. Given my directory dir and my file dir/bar owned by me, which permissions allow me to change or create new content (data) in the file dir/bar but not delete the file? a. Permissions 100 on directory dir and 100 on file dir/bar. b. Permissions 500 on directory dir and 600 on file dir/bar. c. Permissions 400 on directory dir and 400 on file dir/bar. d. Permissions 200 on directory dir and 200 on file dir/bar. e. Permissions 600 on directory dir and 700 on file dir/bar. 9. What is the output of the following sequence of bash commands: echo hi >wc ; wc wc >hi ; cat hi a. 0 0 0 wc b. hi c. no output d. 1 1 3 wc e. 1 1 2 wc 10. What is the output of the following sequence of bash commands: a=cow ; touch $a ; test -z $a ; echo $? a. the number 1 or 0 followed by another 1 or 0 on a new line b. no output c. test: $a: integer expression expected d. 0 e. 1 11. Which of the following shell command lines displays all the names in the current directory that are exactly three letters (alphabetic) long (and nothing else)? a. echo ??? b. echo [a-zA-Za-zA-Za-zA-Z] c. echo [azAZ][azAZ][azAZ] d. echo [a-zA-Z][a-zA-Z][a-zA-Z] e. echo [a,zA,Z][a,zA,Z][a,zA,Z] 70 Questions DAT2330 Unix Final - 30% 100 minutes DAT2330 - Ian Allen - Fall 2003-3- 100 minutes 12. Which command sequence below outputs only lines 10-15 of the Unix password file? a. head -15 /etc/passwd | tail -5 /etc/passwd b. head -15 /etc/passwd | tail -6 c. head -10 /etc/passwd | tail -5 /etc/passwd d. tail -10 /etc/passwd | head -15 /etc/passwd e. tail -15 /etc/passwd | head -5 13. If file foo contains nine lines, each of which is the one- digit line number of the line in the file (1 through 9), what is the output of this command: cat foo foo | sort -r | head -4 | tail -1 a. 8 b. 6 c. 9 d. 7 e. 5 14. Which line below is most likely to be the beginning of an error message? a. echo 2>&1 "... " b. echo 1>&2 "... " c. echo 2<$1 "... " d. echo 1<&2 "... " e. echo 2>$1 "... " 15. Which Unix command sequence deletes a directory and everything inside it? a. rmdir -all dir b. deltree -all dir c. rm -all dir d. rm -r dir e. rmdir -r dir 16. In an empty directory, what is the length of the longest file name created by the following bash shell two-command sequence: var='1 12 123 1234 12345' ; touch '$var' a. 2 characters b. 4 characters c. 1 character d. 3 characters e. 13 characters 17. Which command sequence below does not generate an error message from the last command in the sequence? a. mkdir one one/two ; rmdir one/two b. mkdir foo foo/bar ; rmdir foo c. date >foo ; cp foo/. bar d. cat /etc/passwd > mail idallen@ncf.ca e. mkdir foo ; ln foo bar 70 Questions DAT2330 Unix Final - 30% 100 minutes DAT2330 - Ian Allen - Fall 2003-4- 100 minutes 18. If pig=12 and cat=99 then which of the following bash command lines outputs only the word hi (and nothing else)? a. [pig -eq 12] || echo hi b. [ pig -ne cat ] && echo hi c. [pig!=pig] || echo hi d. [!pig = cat] && echo hi e. [ pig = pig ] && echo hi 19. What is the output of the following sequence of bash commands: x=1 ; y=2 ; test $x -le $y ; echo $? a. the number 0 or 1 followed by another 0 or 1 on a new line b. 1 c. test: $x: integer expression expected d. 0 e. no output 20. What is the output of the following sequence of bash commands: a=1 ; b=2 ; test $a -ge $b ; echo $? a. 1 b. no output c. 0 d. test: $a: integer expression expected e. the number 1 or 0 followed by another 1 or 0 on a new line 21. In an empty directory, what is the shell output of these three commands: touch .1 .2 .3 11 12 ; a='.1* .2*' ; echo '$a' a. 11 .1 12 .2 b. '.1* .2*' c. .1 .2 d. .1* .2* e. $a 22. How many arguments are passed to the command by the shell on this command line: pig pig pig a. 3 b. 5 c. 4 d. 2 e. 6 23. What is the link count of directory dir after this set of successful commands? mkdir dir ; cd dir ; touch foo ; mkdir a b c a. 5 b. 2 c. 1 d. 4 e. 3 24. Which command line below does not show any lines from inside the file pig? a. ls pig b. tail pig c. less pig d. head pig e. more pig 70 Questions DAT2330 Unix Final - 30% 100 minutes DAT2330 - Ian Allen - Fall 2003-5- 100 minutes 25. If variable mt might contain nothing (a null value - defined but empty), which bash command sequence correctly tests for this and prints OK? a. if [ "$mt" = "" ] ; then echo OK ; fi b. if [ $mt -eq "" ] ; then echo OK ; fi c. if [ "$mt" = * ] ; then echo OK ; fi d. if [ ''$mt'' = '''' ] ; then echo OK ; fi e. if [ $mt -eq : ] ; then echo OK ; fi 26. A shell script named foo is executed as follows: ./foo 1 2 "3 4" 5 Inside the script is the line: echo "$3" What is the output from this line? a. 2 3 4 b. "3 c. 3 4 d. 1 2 3 e. $3 27. How can you ask the bash shell to complete commands or file names for you? a. Type [CONTROL]-[D] and the shell will present a menu of commands. b. You can type the first part of the command or file name and press the ALT key. c. Type [ALT]-[F2] the shell will present a menu of commands. d. Type [CONTROL]-[ALT]-[DEL] and the shell will present a menu of commands. e. You can type the first part of the command or file name and press the TAB key. 28. What is the bash shell output of this two-command sequence: cd /bin && echo "echo $(pwd)" a. echo 0pwd) b. echo /bin c. echo $(pwd) d. /bin e. no output 29. If directory dir contains only these five two-character file names: a?, 11, ?1, 1*, .1, then which shell command below will remove only the single two-character name ?1 from the directory? a. rm dir/1* b. rm dir/*1 c. rm dir/?? d. rm dir/?1 e. rm dir/\?? 30. What is the bash shell output of this two-command sequence: cd /etc/passwd && echo "in $(pwd)" a. in /etc b. no output c. in $(pwd) d. bash: cd: /etc/passwd: Not a directory e. in 0pwd) 70 Questions DAT2330 Unix Final - 30% 100 minutes DAT2330 - Ian Allen - Fall 2003-6- 100 minutes 31. What is the bash shell output of this command sequence: false && echo "linux rocks $?" a. linux rocks 1 b. no output c. linux rocks 0 d. linux rocks 1 e. linux rocks 0 32. If file /a contains 40 lines, and file /b contains 60 lines, then how many lines are output by this command: sort /a /b | cat /a | cat /b a. 200 b. 60 c. 40 d. 100 e. 160 33. If file /a contains 20 lines, and file /b contains 30 lines, then how many lines are in file /c after this sequence of shell commands: sort /a /b >/c ; cat /a >>/b ; sort /c /b /a >/c a. 80 b. 120 c. 70 d. 50 e. no lines (empty file) 34. What is the output of the following sequence of bash commands: echo wc >wc ; wc wc >wc ; head wc a. no output b. 1 1 2 wc c. 1 1 3 wc d. wc e. 0 0 0 wc 35. What is the bash shell output of this two-command sequence if run in a directory containing 123 files with names that are all the numbers from 1 to 123 inclusive: glob="*" ; echo "$glob" a. the file names 1 through 123, surrounded by quotes b. * c. "$glob" d. the file names 1 through 123 e. $glob 36. Which command line displays the contents of the Unix passwd file one page at a time? a. less less c. cat /etc/passwd >less d. /etc/passwd | less e. less | /etc/passwd 70 Questions DAT2330 Unix Final - 30% 100 minutes DAT2330 - Ian Allen - Fall 2003-7- 100 minutes 37. What minimal permissions must you have on a directory to be able to execute successfully the command ls . from inside the directory? a. r-x b. rw- c. --x d. -wx e. r-- 38. What is the link count of file foo after this set of successful commands? rm foo ; touch foo ; ln foo bar cp bar x ; ln x y ; ln bar z ; ln z a a. 5 b. 2 c. 3 d. 4 e. 1 39. Which of the command lines below can generate a non-empty file? a. tr abc ABC /out b. tail -5 /out >/out c. ls /out >/out d. sort -r /out >/out e. grep -v /out /out >/out 40. If a=xxx and b=yyy then what is the output of the following sequence of bash commands: if $a = $b ; then echo $a ; fi a. test: xxx: integer expression expected b. bash: xxx: command not found c. no output d. xxx e. test: $a: integer expression expected 41. Given my directory dir and my file dir/bar owned by me, which permissions allow me to delete the file dir/bar from the directory, but not change the content (data) in the file? a. Permissions 100 on directory dir and 100 on file dir/bar. b. Permissions 100 on directory dir and 200 on file dir/bar. c. Permissions 300 on directory dir and 500 on file dir/bar. d. Permissions 500 on directory dir and 400 on file dir/bar. e. Permissions 300 on directory dir and 300 on file dir/bar. 42. What is the output of the following sequence of bash commands: x=0 ; test $x ; echo $? a. no output b. test: $x: integer expression expected c. the number 0 or 1 followed by another 0 or 1 on a new line d. 0 e. 1 70 Questions DAT2330 Unix Final - 30% 100 minutes DAT2330 - Ian Allen - Fall 2003-8- 100 minutes 43. If my current working directory is /home, and my home directory is /home/xx, which of the of the following commands copies the Unix password file into my home directory under the name foo? a. cp xx/../../etc/passwd xx/foo b. cp xx/../etc/passwd ../home/xx/foo c. cp ../etc/passwd ../xx/foo d. cp ../home/xx/../etc/passwd ./xx/./foo e. cp ../../etc/passwd /xx/foo 44. Which of the following statements is true about this shell command line: >bar zoom bar haven a. The command bar sees three arguments. b. Error: The command name is missing from the command line. c. The command zoom sees three arguments. d. The command bar sees only two arguments e. The command zoom sees two arguments. 45. How many arguments and options are there to the command: sort -r c ; echo b >>c ; mv c d >file a. a b. b c. a followed by b d. no such file (nonexistent file) e. nothing - file is empty - no data 56. If directory /dir contains these three four-character file names: .123, .124, .???, then what is the output of the following bash shell command line: echo /dir/???? a. /dir/.123 /dir/.124 b. /dir/.123 /dir/.124 /dir/.??? c. no output d. echo: /dir/????: No such file or directory e. /dir/???? 57. If a bash shell script named foo contains the line: if [ "$1" = '$2' ] ; then echo SAME ; fi then which of the following command lines will produce SAME as output? a. ./foo "$1" '$2' b. ./foo bar bar c. ./foo '$2' bar d. ./foo $2 $2 e. ./foo "bar" 'bar' 58. What is the output of this sequence of three shell commands: umask 762 ; touch newfile ; ls -l newfile a. -rwxrw--w- 1 me me 0 Oct 1 1:12 newfile b. --------wx 1 me me 0 Oct 1 1:12 newfile c. -rw-rw--w- 1 me me 0 Oct 1 1:12 newfile d. -------r-- 1 me me 0 Oct 1 1:12 newfile e. ------xr-x 1 me me 0 Oct 1 1:12 newfile 59. If /bin/pig is a program that outputs hi and /usr/bin/pig is a program that outputs foo what is the output of this shell command sequence: PATH=/etc:/usr/bin:/bin ; pig a. foo followed by hi b. foo c. hi d. hi followed by mom e. bash: pig: command not found 60. Which of the following shell command lines displays the names in the current directory that are exactly three numeric digits long (and nothing else)? a. echo [0-9][0-9][0-9] b. echo ??? c. echo [0-90-90-9] d. echo [1-31-31-3] e. echo [1-3][1-3][1-3] 70 Questions DAT2330 Unix Final - 30% 100 minutes DAT2330 - Ian Allen - Fall 2003-11- 100 minutes 61. Which line below puts the count of the number of lines in the password file into the variable foo? a. foo=[ grep -c /etc/passwd ] b. foo=$( wc -l