50 M/C Questions -1- 50 M/C Questions -2- 6. [55/116] What is the output on your screen of the following sequence of PRINT Name: LAB Section: commands: i=00 ; [ $i -eq 0 ] ; echo $? Test Version: ___ One-Answer Multiple Choice 50 Questions − 10 of 10% a. the number 0 or 1 followed by another 0 or 1 on a new line b. 0 ☞ Read all the words of these instructions and both sides (back and front) of all pages. c. no output ☞ Use your full, unabbreviated name on the mark-sense form. Do not abbreviate your name. d. test: $i: integer expression expected ☞ Put the three-digit Test Version above into NO. OF QUESTIONS and NO. OF STUDENTS e. 1 ☞ Fill in the bubbles with pencil only, no pen. Enter your NAME, Test Version, and answers. ☞ Manage your time. Answer questions you know, first. One Answer per question. 7. [55/115] If the current directory contains files abc, bbc, cbc, and bbc contains just the line dbd, what is the output of the following command: grep 'b*$' bbc 1. [28/116] What would be the output of the following command line: a. cbc b. no output c. an error message echo a b c | awk '{print NF}' d. dbd e. bbc a. a b c b. no output c. c 8. [56/115] If exfor is an executable script containing the line for myvar;do d. NF e. 3 echo -n "$myvar ";done, what is the output of the script 2. [34/116] Which of the following options for bash or sh might be useful for ./exfor one two three debugging a shell script? a. one two three b. no output c. three a. -r b. -z c. -c d. -x e. -l d. two three e. one 3. [44/116] What is the output of this sequence of three shell commands: 9. [57/116] Which command will help you track how many subshells deep your umask 527 ; touch newfile ; ls -l newfile current shell is? a. --w-r-x--- 1 me me 0 Oct 1 1:12 newfile a. shlvl b. echo "$SHLVL" c. runlevel b. --w-r----- 1 me me 0 Oct 1 1:12 newfile d. sh e. bash c. -rwxrw---x 1 me me 0 Oct 1 1:12 newfile 10. [64/116] If a=3 and b=4 then what is the output on your screen of the following d. -rw-rw---- 1 me me 0 Oct 1 1:12 newfile sequence of commands: [ "$a" -eq 3 -o "$b" -eq 3 ]; echo "$?" e. -r-x-w-rwx 1 me me 0 Oct 1 1:12 newfile a. number 1 or 0 followed by 1 or 0 on a new line 4. [48/115] If foo is a script containing the line TERM=new ; export TERM, b. 0 what is the output of the following sequence of bash commands that use foo: c. [: $a: string expression expected TERM=bar ; ./foo ; echo '$TERM' d. 1 a. TERM b. new c. $TERM d. bar e. foo e. no output 5. [52/116] If ./a/b were a readable empty file, what would be the bash shell 11. [65/116] If dog is an executable script containing the line: umask 0077 output of this two command sequence: what is the output of the following sequence of commands: PATH=/etc/:/usr:/var ; /bin/cat ./a/b umask 0022 ;source dog ; umask a. /bin/cat: ./a/b: No such file or directory a. 0075 b. no output on screen c. 0077 b. bash: cat: command not found d. 0022 e. 0079 c. no output 12. [68/116] What is the output on your screen of the following sequence of d. bash: /bin/cat: command not found commands: x=pig ; y=cow ; [ -z $x ] ; echo $? e. bash: ls: command not found a. the number 0 or 1 followed by another 0 or 1 on a new line b. test: $x: integer expression expected c. 0 d. 1 e. no output CST 8177 − Winter 2015 − Midterm Test #1 − 10% Wenjuan Jiang & Ian Allen CST 8177 − Winter 2015 − Midterm Test #1 − 10% Wenjuan Jiang & Ian Allen 50 M/C Questions -3- 50 M/C Questions -4- 13. [68/116] If the file foo in the current directory contains just two lines dbd, and 19. [73/116] What is true about this output from ls -il foo bar 123, what is the output of the following command: 24 -rwxr----- 3 root root 2 Jul 31 12:33 foo grep '[[:alnum:]]' foo 24 -rwxr----- 3 root root 2 Jul 31 12:33 bar a. foo b. no output or an error message a. foo and bar are names for different files c. 123 d. both lines b. foo and bar are two of three names for this file e. dbd c. foo and bar are names for the same file 14. [69/116] Who is the owner of file bar after you successfully execute this sequence d. this output is not possible of commands in your home directory: e. foo and bar each have two names (four names total) touch foo ; ln foo one ; ln one two ; ln two bar 20. [74/116] If a=123 and b=456 then what is the output of the following sequence a. you own the file bar of bash commands: if [ $a = $b ]; then echo $a ; fi b. the file is owned by home a. bash: 123: command not found c. the file is owned by passwd b. 123 d. the file is owned by root c. no output e. you cannot execute the given commands; no file will be created d. test: $a: string expression expected 15. [71/116] What is the output on your screen of the following command sequence: e. test: a=123: integer expression expected i=04; test $i = 4 ; echo $? 21. [75/116] If the current directory contains files abc, bbc, cbc, and bbc contains a. 0 just the line bbb, what is the output of the following command: grep bb* bbc b. no output a. bbc b. no output c. cbc c. 1 d. dbd e. an error message d. the number 0 or 1 followed by another 0 or 1 on a new line 22. [75/116] If the current directory contains files abc, bbc, cbc, and bbc contains e. test: $i: integer expression expected just the line dbd, what is the output of the following command: 16. [71/116] If the file foo in the current directory contains just the line abc123, grep "^bb*" bbc what is the output of the following command: grep '^[[:alpha:]]' foo a. dbd b. cbc c. no output a. an error message b. no output c. abc123 d. bbc e. an error message d. 123 e. abc 23. [76/116] Which line below puts the count of the number of lines in the password 17. [72/116] What is the correct syntax to redirect both standard output and standard file into the variable foo? error into the same output file? a. foo=$( wc -l out >out b. command 2>1 >out b. foo=$( cat -c /etc/passwd ) c. command >out 2>1 d. command >out 2>&1 c. foo=$( wc /etc/passwd | awk echo $1 ) e. command 2>&1 >out d. foo=$( awk -F: /etc/passwd | wc -l ) 18. [72/115] If there is a file foo in the current directory contains just the line abcd, e. foo=$( wc -l /etc/passwd | awk "print $1" ) what is the output of the following command: 24. [78/115] If bar is an executable script containing the line animal=dog then [ -e foo ] && rm foo; cat foo what is the bash output of this sequence of three commands: a. cat: foo: No such file or directory animal=pig ; ./bar ; echo "the '$animal' ate" b. 0 a. the 'pig' ate b. the '$cow' ate c. no output c. the 'dog' ate d. the 'cow' ate d. foo e. the $cow ate e. abcd 25. [79/116] What is the output of this successful command line? cd /home/myhome ; mkdir foo ; mkdir bar ; cd a. /home/myhome/foo b. no output c. /home/myhome d. /bar e. /home/myhome/bar CST 8177 − Winter 2015 − Midterm Test #1 − 10% Wenjuan Jiang & Ian Allen CST 8177 − Winter 2015 − Midterm Test #1 − 10% Wenjuan Jiang & Ian Allen 50 M/C Questions -5- 50 M/C Questions -6- 26. [80/116] Which of these statements is true? 33. [96/114] Which bash command sequence correctly compares the two numbers a. Typing ./script and bash script always give identical results. and prints OK? b. The ls dir command looks up the directory argument dir in your $PATH . a. if ( ! 4 < 3 ) ; then echo OK ; fi c. If ./q is an empty directory, echo ./q/.* produces an error message. b. if [ 4 -ge 3 ] ; then echo OK ; fi d. Double quotes will stop shell glob (wildcard) patterns from expanding. c. if [ ! 4 -gt 3 ] ; then echo OK ; fi e. If ./p is an empty directory, ls ./p/.* produces an error message. d. if [ 4 > 3 ] ; then echo OK ; fi 27. [83/116] In an empty directory, what appears on your screen after this bash e. if ( 3 < 4 ) ; then echo OK ; fi command line? ls 1>/dev/null nosuchfile 34. [97/116] What minimal permissions must you have on a directory to be able to a. ls: nosuchfile: No such file or directory execute successfully the command ls . from inside the directory? b. ls: 1>/dev/null nosuchfile: No such file or directory a. r-- b. --x c. -wx d. r-x e. rw- c. nosuchfile 35. [97/116] Which of these commands makes a file owned by me, also writable by d. ls: /dev/null: No such file or directory me? e. no output a. umask 777 myfile b. chmod x=u ./myfile 28. [84/115] What is the output on your screen of the following sequence of c. chmod u+w myfile d. chmod u+x ./myfile commands: a=4 ; b=4 ; [ $a -le $b ] ; echo $? e. umask 111 myfile a. 1 36. [97/116] Which of these statements is true? b. 0 a. To make a hard link to file "foo" named "bar", file "foo" must exist. c. test: $a: integer expression expected b. You can make a hard link to a directory. d. no output c. You only need "r--" permission on directory "foo" for "ls -l foo" to work. e. the number 1 or 0 followed by another 1 or 0 on a new line d. If you give me write permission on a file owned by you, I can then use chmod to 29. [85/115] Given the following bash shell command line: change its permissions. read xx yy zz e. The "ln" command takes two arguments, so the maximum number of hard links which user keyboard input line below will assign the text 22 to the shell variable a file can have is two. named zz? 37. [98/116] If /etc/passwd is a file name, which of the following pathnames a. 11 33 22 b. xx=11 zz=22 yy=33 always leads to the same file? c. 22 33 11 d. 11 22 33 a. /etc/passwd/../.. b. /etc/../../passwd e. 11;22;33 c. /etc/passwd/. d. ./etc/passwd 30. [86/116] A shell script named bar is executed as follows: e. /etc/../etc/passwd ./bar "a b" "c d e" f 38. [98/116] What is the output of the following sequence of bash commands: Inside the script is the line: echo "$3" a=1 ; b=2 ; test $a -ge $b ; echo $? What is the output on your screen from this line? a. 1 a. $3 b. f c. "f" d. c d e e. a b b. 0 31. [87/116] Which of the following regular expressions would match lines that contain c. the number 1 or 0 followed by another 1 or 0 on a new line no white space? d. no output a. [^:space:]* b. [^[:space:]]*$ e. test: $a: integer expression expected c. ^[^[:space:]]*$ d. [^[:space:]]* 39. [99/115] Which of the following regular expressions would match lines that contain e. ^[[:space:]]*$ one or more alphanumeric characters only? 32. [94/115] Which of these command lines will make file cow contain all of the a. ^[[:alnum:]]*$ content of file one followed by all of the content of file two? b. [[:alnum:]][[:alnum:]]* a. cat one two >cow b. mv one two >cow c. [a-z0-9][a-z0-9]* c. cp one two >cow d. echo one two >cow d. [[:alnum:]]* e. cp one >cow two >cow e. ^[[:alnum:]][[:alnum:]]*$ CST 8177 − Winter 2015 − Midterm Test #1 − 10% Wenjuan Jiang & Ian Allen CST 8177 − Winter 2015 − Midterm Test #1 − 10% Wenjuan Jiang & Ian Allen 50 M/C Questions -7- 50 M/C Questions -8- 40. [100/115] What is in file myfile after running this bash shell command line? 47. [107/116] In the output of the command ls -a, a dot that begins a name signifies echo one > myfile two three what? a. echo two three b. one two three a. The current directory. c. no output (empty file) d. two myfile three b. A name that is hidden. e. three c. A current file. 41. [102/116] Which command sequence creates a directory into which anyone can put d. The parent directory. a file, but in which nobody can see the names of the files that are there? e. A name with an unprintable character. a. mkdir protected ; cd protected ; chmod go+wx . 48. [107/115] What is the result of this exact command line: b. mkdir protected ; chmod 777 protected echo /etc/passwd ls c. mkdir protected ; cd protected ; chmod go-x . a. file "/etc/passwd" will be copied to "hello"; the names will be displayed as well d. mkdir protected ; chmod 777 . b. the text "/etc/passwd" and "ls" will be displayed e. mkdir protected ; chmod 333 protected c. the contents of the files "/etc/passwd" and "hello" will be displayed 42. [102/116] If the file foo in the current directory contains just the line dbd, what is d. all the files under "/etc/passwd" with the name "hello" will be displayed the output of the following command: grep '[[:alpha:]]' foo e. a list of file names matching "/etc/passwd" and "hello" will be displayed a. 123 b. dbd c. an error message 49. [110/116] What would you type to change the permissions on a file to d. no output e. foo rwxr-xr--? 43. [103/116] Which line does not match the following extended Regex? a. chmod 754 file b. chmod 244 file grep -E '[pP][aA][sS]{2}w[d|ord]$' c. chmod 311 file d. chmod 744 file a. passwd b. pAsSwd c. password e. chmod 211 file d. PASSword e. passwD 50. [110/116] Which command line would show the inode number of a file? 44. [103/115] Which command below removes only this five-character file name a. cat -ia file b. cat -la file c. ls -la file containing a special character (and no others): *test d. ps -la file e. ls -ia file a. rm '*test' b. rm \\*test c. rm ./\\*test d. rm ./*test e. rm *test 45. [104/116] If cow is a sub-directory that contains only the file dog, what happens after this command: mv cow/././dog cow/cat a. there is a second copy of the file dog in the file named cat b. the command fails because the name cow/././dog does not exist c. the directory cow now contains only a file named cat d. the directory cow is now empty e. the command fails because the name cat does not exist 46. [106/115] Which of the following is true, given this long directory listing from ls: 755 drwxr-x--x 256 wen user 1024 May 30 12:35 dir a. The number 256 is the octal permissions of this directory. b. The number 256 is the inode number of this directory. c. The number 755 is the count of links (names) this directory has. d. The number 1024 is the size of this directory. e. The number 1024 is the count of links (names) this directory has. CST 8177 − Winter 2015 − Midterm Test #1 − 10% Wenjuan Jiang & Ian Allen CST 8177 − Winter 2015 − Midterm Test #1 − 10% Wenjuan Jiang & Ian Allen