Unix Test #2 DAT2330 - Ian Allen - Winter 20-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: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70) 1. If a=1 and b=1, which bash command sequence correctly compares the two numbers as equal and prints OK? a. if [ $a -eq $b ] ; then echo OK ; fi b. if test a -eq b ; then echo OK ; fi c. if [ a = b ] ; then echo OK ; fi d. if ( a == b ) ; then echo OK ; fi e. if [ $a==$b ] ; then echo OK ; fi 2. If variable x might contain nothing (a null value - defined but empty), which bash command sequence correctly tests for this and prints OK? a. if [ "$x" = "" ] ; then echo OK ; fi b. if [ $x -eq : ] ; then echo OK ; fi c. if [ $x -eq "" ] ; then echo OK ; fi d. if [ ''$x'' = '''' ] ; then echo OK ; fi e. if [ "$x" = * ] ; then echo OK ; fi 3. If a=aaa and b=bbb then what is the output of the following sequence of bash commands: if $a = $b ; then echo $a ; fi a. bash: aaa: command not found b. test: aaa: integer expression expected c. test: $a: integer expression expected d. aaa e. no output 4. If a=ant and b=bat then what is the output of the following sequence of bash commands: [ $a = bat -o $b = bat ] ; echo $? a. 0 b. 1 c. the number 1 or 0 followed by another 1 or 0 on a new line d. test: $a: integer expression expected e. no output 70 Questions DAT2330 Unix Final - 30% 100 minutes DAT2330 - Ian Allen - Winter 20-2- 100 minutes 5. If a=ant and b=bat then what is the output of the following sequence of bash commands: [ $a = ant -a $b = ant ] ; echo $? a. 1 b. 0 c. the number 1 or 0 followed by another 1 or 0 on a new line d. test: $a: integer expression expected e. no output 6. What is the output of the following sequence of bash commands: echo wc >wc ; wc wc >wc ; head wc a. 0 0 0 wc b. 1 1 3 wc c. 1 1 2 wc d. no output e. wc 7. What is the output of the following sequence of bash commands: echo hi >wc ; wc wc >hi ; cat hi a. 1 1 3 wc b. 0 0 0 wc c. 1 1 2 wc d. no output e. hi 8. What is the output of the following sequence of bash commands: date='Friday March 12' ; test date = date a. no output b. Fri Mar 12 10:20:39 EST 2004 c. 1 d. 0 e. test: too many arguments 9. What is the output of the following sequence of bash commands: f=1 ; touch f ; test ! -z $f ; echo $? a. 0 b. 1 c. the number 1 or 0 followed by another 1 or 0 on a new line d. test: $f: integer expression expected e. no output 10. What is the output of the following sequence of bash commands: a=sky ; touch $a ; test -z $a ; echo $? a. 1 b. 0 c. sky d. test: $a: integer expression expected e. no output 11. What is the output of the following sequence of bash commands: i=0 ; test $i = 00 ; echo $? a. 1 b. 0 c. the number 0 or 1 followed by another 0 or 1 on a new line d. test: $i: integer expression expected e. no output 70 Questions DAT2330 Unix Final - 30% 100 minutes DAT2330 - Ian Allen - Winter 20-3- 100 minutes 12. What is the output of the following sequence of bash commands: a=1 ; b=2 ; test $a -ge $b ; echo $? a. 1 b. 0 c. the number 1 or 0 followed by another 1 or 0 on a new line d. test: $a: integer expression expected e. no output 13. What is the output of the following sequence of bash commands: x=1 ; y=2 ; test $x -le $y ; echo $? a. 0 b. 1 c. the number 0 or 1 followed by another 0 or 1 on a new line d. test: $x: integer expression expected e. no output 14. What is the bash shell output of this two-command sequence: cd /etc/passwd && echo "in $(pwd)" a. bash: cd: /etc/passwd: Not a directory b. in /etc c. in 0pwd) d. in $(pwd) e. no output 15. What is the bash shell output of this two-command sequence: cd /bin && echo "echo $(pwd)" a. echo /bin b. echo 0pwd) c. echo $(pwd) d. /bin e. no output 16. In an empty directory, what is the length of the longest file name created by the following bash shell two-command sequence: var='a ab abc abcd abcde' ; touch '$var' a. 4 characters b. 3 characters c. 2 characters d. 1 character e. 13 characters 17. Which bash command sequence correctly searches for the chars and then prints OK if it is found inside the password file? a. if grep chars bat bat bat a. 4 b. 5 c. 2 d. 3 e. 6 70 Questions DAT2330 Unix Final - 30% 100 minutes DAT2330 - Ian Allen - Winter 20-7- 100 minutes 35. 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 500 on directory dir and 600 on file dir/bar. b. Permissions 100 on directory dir and 100 on file dir/bar. c. Permissions 200 on directory dir and 200 on file dir/bar. d. Permissions 400 on directory dir and 400 on file dir/bar. e. Permissions 600 on directory dir and 700 on file dir/bar. 36. 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 300 on directory dir and 500 on file dir/bar. b. Permissions 100 on directory dir and 200 on file dir/bar. c. Permissions 100 on directory dir and 100 on file dir/bar. d. Permissions 300 on directory dir and 300 on file dir/bar. e. Permissions 500 on directory dir and 400 on file dir/bar. 37. 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. 3 c. 1 d. 2 e. 4 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. 4 b. 3 c. 1 d. 2 e. 5 39. 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 [a-zA-Z][a-zA-Z][a-zA-Z] 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 ??? 40. 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 [0-90-90-9] c. echo [1-3][1-3][1-3] d. echo [1-31-31-3] e. echo ??? 70 Questions DAT2330 Unix Final - 30% 100 minutes DAT2330 - Ian Allen - Winter 20-8- 100 minutes 41. 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. 70 b. 50 c. 80 d. 120 e. no lines (empty file) 42. 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. 60 b. 40 c. 100 d. 160 e. 200 43. What is in the file named file after this command sequence: echo a >c ; echo b >>c ; mv c d >file a. nothing - file is empty - no data b. a followed by b c. a d. b e. no such file (nonexistent file) 44. What is the output of this command sequence: echo bat >one ; echo sky | head -2 one a. bat b. sky c. bat followed by sky d. sky followed by bat e. an error message 45. 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/???? b. /dir/.123 /dir/.124 /dir/.??? c. /dir/.123 /dir/.124 d. echo: /dir/????: No such file or directory e. no output 46. 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/\?? b. rm dir/?1 c. rm dir/1* d. rm dir/*1 e. rm dir/?? 70 Questions DAT2330 Unix Final - 30% 100 minutes DAT2330 - Ian Allen - Winter 20-9- 100 minutes 47. Which of the following bash PATH statements makes the most sense? a. PATH=/bin:/usr/bin:/etc b. PATH=/bin:/usr/bin:/etc/passwd c. PATH=/bin/ls:/etc:/usr/bin d. PATH=/bin:/bin/cat:/usr/bin e. PATH=/bin/sh:/usr/bin:/etc:/bin 48. Which of the following statements is true about this shell command line: >bar zoom bar haven a. The command zoom sees two arguments. b. The command zoom sees three arguments. c. The command bar sees only two arguments d. The command bar sees three arguments. e. Error: The command name is missing from the command line. 49. Which command sequence below outputs only lines 10-15 of the Unix password file? a. head -15 /etc/passwd | tail -6 b. tail -15 /etc/passwd | head -5 c. head -15 /etc/passwd | tail -5 /etc/passwd d. head -10 /etc/passwd | tail -5 /etc/passwd e. tail -10 /etc/passwd | head -15 /etc/passwd 50. 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 ; ln foo bar c. date >foo ; cp foo/. bar d. cat /etc/passwd > mail idallen@ncf.ca e. mkdir foo foo/bar ; rmdir foo 51. If the file bat 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 bat a. bat b. foo c. /bin/ls: bat: No such file or directory d. bash: /bin/ls: command not found e. no output 52. If /bin/bat is a program that outputs hi and /usr/bin/bat is a program that outputs foo what is the output of this shell command sequence: PATH=/etc:/usr/bin:/bin ; bat a. foo b. hi c. foo followed by hi d. hi followed by mom e. bash: bat: command not found 53. Which of these commands makes a file owned by me, also executable by me? a. chmod u+x ./myfile b. chmod x+u myfile c. chmod x=u ./myfile d. umask 777 myfile e. umask 111 myfile 70 Questions DAT2330 Unix Final - 30% 100 minutes DAT2330 - Ian Allen - Winter 20-10- 100 minutes 54. Which of these first lines will cause this executable file to be interpreted using the Bash shell? a. #!/bin/bash b. #/bin/bash c. !#/bin/bash -u d. !/bin/bash e. /bin/bash -u 55. Which command line below does not show any lines from inside the file bat? a. ls bat b. head bat c. tail bat d. more bat e. less bat 56. Which command line displays the contents of the Unix passwd file one page at a time? a. less less d. /etc/passwd | less e. cat /etc/passwd >less 57. Which line below is most likely to be the beginning of an error message? a. echo 1>&2 "... " b. echo 1<&2 "... " c. echo 2>&1 "... " d. echo 2<$1 "... " e. echo 2>$1 "... " 58. Which line below puts the count of the number of lines in the password file into the variable foo? a. foo=$( wc -l /out b. sort -r /out >/out c. tail -5 /out >/out d. tr abc ABC /out e. grep -v /out /out >/out 65. What is the bash shell output of this two command sequence: PATH=/bin/ls:/bin/head:/bin/sh ; head nosuchfile a. bash: head: command not found b. bash: /bin/ls: command not found c. ls: /bin/head: command not found d. head: nosuchfile: No such file or directory e. bash: /bin/sh: No such file or directory 66. What is the output of this sequence of three shell commands: echo x >abc ; ls >abc abc ; wc abc a. 1 1 4 abc b. 1 1 3 abc c. 1 1 2 abc d. 0 0 0 abc e. no output 70 Questions DAT2330 Unix Final - 30% 100 minutes DAT2330 - Ian Allen - Winter 20-12- 100 minutes 67. How can you ask the bash shell to complete commands or file names for you? a. You can type the first part of the command or file name and press the TAB key. b. You can type the first part of the command or file name and press the ALT key. c. Type [CONTROL]-[ALT]-[DEL] and the shell will present a menu of commands. d. Type [CONTROL]-[D] and the shell will present a menu of commands. e. Type [ALT]-[F2] the shell will present a menu of commands. 68. Given this long listing: drwxr-xr-x 448 me me 296 Dec 4 9:12 /dir How many subdirectories lie immediately under /dir? a. 446 b. 448 c. 294 d. 296 e. there is not enough information shown to answer the question 69. 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. --x c. r-- d. -wx e. rw- 70. Select the correct bash shell order of command line processing: a. aliases, redirection, variables, globs b. aliases, variables, redirection, globs c. aliases, variables, globs, redirection d. aliases, globs, variables, redirection e. redirection, aliases, globs, variables 70 Questions DAT2330 Unix Final - 30% 100 minutes DAT2330 - Ian Allen - Winter 20-13- 100 minutes Answer Key - DAT2330 - Ian Allen - Winter 2004 - DAT2330 Unix Final - 30% Office use only: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 1. a 49. a 2. a 50. a 3. a 51. a 4. a 52. a 5. a 53. a 6. a 54. a 7. a 55. a 8. a 56. a 9. a 57. a 10. a 58. a 11. a 59. a 12. a 60. a 13. a 61. a 14. a 62. a 15. a 63. a 16. a 64. a 17. a 65. a 18. a 66. a 19. a 67. a 20. a 68. a 21. a 69. a 22. a 70. a 23. a 24. a Count of a: 70 100% 25. a 26. a With 5 choices: 70 27. a 1 2 3 4 5 6 7 8 9 10 11 12 13 28. a 14 15 16 17 18 19 20 21 22 23 29. a 24 25 26 27 28 29 30 31 32 33 30. a 34 35 36 37 38 39 40 41 42 43 31. a 44 45 46 47 48 49 50 51 52 53 32. a 54 55 56 57 58 59 60 61 62 63 33. a 64 65 66 67 68 69 70 34. a 35. a Macro .cmd splits: 27 36. a Macro .ans splits: 0 37. a 38. a 39. a 40. a 41. a 42. a 43. a 44. a 45. a 46. a 47. a 48. a 70 Questions DAT2330 Unix Final - 30% 100 minutes