Practice Test #2 Questions - answers at end 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 - 157 Questions This is a practice test containing many practice questions. The real test will contain some questions similar to these. There are probably many more questions in this practice test than there will be time for in the real test. The real test will have approximately one question per minute. The real test may have some questions unlike anything given here. Knowing the concepts behind the questions is necessary; memorizing these specific answers won't help. The answers to this test are in the Answer Key on the last page(s). 1. If directory /000 contains these three four-character file names: .abc, .xyz, .???, then what is the output on your screen of the following command line: echo /000/???? a. echo: /000/????: No such file or directory b. /000/???? c. no output d. /000/.abc /000/.xyz e. /000/.abc /000/.xyz /000/.??? 2. What is the output on your screen of the following sequence of commands: false && echo "foo bar $?" a. no output b. foo bar 0 c. foo bar 0 d. foo bar 1 e. foo bar 1 3. What is the output on your screen of the following command sequence: cd /etc/passwd && echo "in $(pwd)" a. bash: cd: /etc/passwd: Not a directory b. in $(pwd) c. no output d. in /etc e. in 0pwd) 4. How many arguments are passed to the command by the shell on this command line: bat bat bat a. 4 b. 2 c. 3 d. 5 e. 6 5. Given my directory dir and my file dir/bar owned by me, which permissions allow me to access and change the content (data) in the file dir/bar but not delete the file? a. Permissions 700 on directory dir and 300 on file dir/bar. b. Permissions 300 on directory dir and 500 on file dir/bar. c. Permissions 600 on directory dir and 200 on file dir/bar. d. Permissions 500 on directory dir and 500 on file dir/bar. e. Permissions 100 on directory dir and 200 on file dir/bar. 6. If your PATH variable contains /bin:/usr/bin, what is the output on your screen of this command line: echo '$PATH' a. /bin:/usr/bin b. $PATH c. '$PATH' d. echo: $PATH: No such file or directory e. '/bin:/usr/bin' 7. What is the output on your screen of this two-command sequence: cd /home || echo "cd $(pwd)" a. cd $(pwd) b. cd 0pwd) c. no output d. /home e. cd /home 8. Which of the following statements is true about this shell command line: >foo file bar haven a. Error: The command name is missing from the command line. b. The command foo sees three arguments. c. The command file sees two arguments. d. The command foo sees only two arguments e. The command file sees three arguments. 9. If happy were a file of text containing 50 different lines, what would be the output on your screen of this exact command line: cp happy sad ; diff happy sad a. no output b. the contents of file happy would be displayed 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. an error message because diff doesn't allow different file names 10. What is the output on your screen of this two-command sequence: cd /etc || echo "cd $(pwd)" a. cd 0pwd) b. cd /etc c. no output d. cd $(pwd) e. /etc 11. What is the link count of directory d after this set of successful commands? mkdir d ; touch f ; cd d ; ln ../f x a. 3 b. 4 c. 2 d. 5 e. 1 12. Which of the following PATH statements makes the most sense? a. PATH=/bin:/usr/bin:/etc/passwd b. PATH=/dev:/bin:/usr/bin:/etc c. PATH=/bin:/bin/cat:/usr/bin d. PATH=/bin/ls:/etc:/usr/bin e. PATH=/dev/null:/usr/bin:/etc:/bin 13. What is the output on your screen if a user signals an end-of-file from the keyboard during this command sequence? read input || echo $? a. 1 b. an error message c. $? d. 0 e. no output on screen 14. What is the output on your screen of this sequence of three shell commands: echo ls >cat ; >cat ls cat ; wc cat a. 1 1 2 cat b. 1 1 3 cat c. 0 0 0 cat d. 1 1 4 cat e. no output 15. What is the output on your screen of the following sequence of commands: x=ok ; y=ok ; [ x = y ] a. no output b. 0 c. 1 d. bash: x: command not found e. test: x: integer expression expected 16. What appears on your screen after this sequence of commands: echo 1 >x ; ln x y ; echo 2 >>y ; sort x a. 1 b. empty file - no output on the screen c. 2 followed by 1 d. 1 followed by 2 e. 2 17. What is the output on your screen of the following command sequence: cd /bin && echo "echo $(pwd)" a. echo $(pwd) b. echo /bin c. echo 0pwd) d. /bin e. no output 18. If a 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 bar '$1' b. ./foo 1 "$1" c. ./foo bar 'bar' d. ./foo $1 $1 e. ./foo 'bar' "bar" 19. What is the output on your screen of this command sequence: echo bat >pig ; echo one | tail pig a. one b. bat c. bat followed by one d. one followed by bat e. an error message 20. Given my directory ddd and my file ddd/fff owned by me, which permissions allow me to delete the file from the directory, but not change the content (data) in the file? a. Permissions 100 on directory ddd and 100 on file ddd/fff. b. Permissions 300 on directory ddd and 500 on file ddd/fff. c. Permissions 100 on directory ddd and 200 on file ddd/fff. d. Permissions 500 on directory ddd and 400 on file ddd/fff. e. Permissions 300 on directory ddd and 300 on file ddd/fff. 21. If dog is an executable script containing the line: umask 0002 what is the output on your screen of the following sequence of commands: umask 0077 ; ./dog ; umask a. no output on screen b. 0075 c. 0002 d. 0079 e. 0077 22. Which of these commands makes a file owned by me, also readable by me? a. umask 400 myfile b. chmod r=u ./myfile c. umask 300 ./myfile d. chmod u+r ./myfile e. chmod r+u myfile 23. If cow=cow and pig=pig then which of the following command lines outputs only the date (and nothing else)? a. test cow -ne pig && date b. [!cow = pig] && date c. [cow!=cow] || date d. test cow = cow && date e. [cow -ne pig] || date 24. Which line below passes three separate arguments to the cat command when placed inside a shell script named foo invoked by the command line: ./foo one two three a. cat "$@" b. cat "$1 $2 $3" c. cat "$? $? $?" d. cat "$#" e. cat "$*" 25. What is the output on your screen of this sequence of three shell commands: echo ls >fil ; >fil ls fil ; wc fil a. 1 1 4 fil b. no output c. 1 1 2 fil d. 0 0 0 fil e. 1 1 3 fil 26. What is the output on your screen of this command sequence: echo pig >one ; echo bat | tail one a. an error message b. bat c. bat followed by pig d. pig followed by bat e. pig 27. What is the output on your screen of the following sequence of commands: x=0 ; y=1 ; touch $x ; test ! -z $x ; echo $? a. test: $x: integer expression expected b. the number 1 or 0 followed by another 1 or 0 on a new line c. 1 d. 0 e. no output 28. Which command sequence below always outputs just the date only if the first argument is either readable or executable? a. if [ "-r $1" || "-x $1" ]; then date ; fi b. if [ -r -o -x "$1" ]; then date ; fi c. if [ -r || -x "$1" ]; then date ; fi d. if [ "$1" -eq -r -o "$1" -eq -x ]; then date ; fi e. if [ -r "$1" -o -x "$1" ]; then date ; fi 29. If a=1 and b=1, which command sequence correctly compares the two numbers as equal and prints OK? a. if test a == b ; then echo OK ; fi b. if [ $a==$b ] ; then echo OK ; fi c. if test $b -eq $a ; then echo OK ; fi d. if [ b = a ] ; then echo OK ; fi e. if [ a -eq b ] ; then echo OK ; fi 30. What is the output on your screen of the following sequence of commands: x=pig ; y=bat ; touch $x ; [ -z $x ] ; echo $? a. 1 b. test: $x: integer expression expected c. no output d. 0 e. the number 0 or 1 followed by another 0 or 1 on a new line 31. What will appear on your screen if you execute this sequence of commands: echo 1 >a ; ln a b ; echo 2 >b ; chmod 266 b ; cat a a. 2 b. 1 followed by 2 c. 1 d. no output on screen e. an error message 32. If variable a might contain nothing (a null value - defined but empty), which command sequence correctly tests for this and prints the date? a. if test "" = "$a" ; then date ; fi b. if [ $a = /dev/null ] ; then date ; fi c. if [ '''' = ''$a'' ] ; then date ; fi d. if test "" -eq $a ; then date ; fi e. if [ "$a" = * ] ; then date ; fi 33. What is the output on your screen of the following sequence of commands: i=0 ; test $i = 00 ; echo $? a. no output b. the number 0 or 1 followed by another 0 or 1 on a new line c. test: $i: integer expression expected d. 1 e. 0 34. Which of these commands makes a file owned by me, also executable by me? a. umask 111 myfile b. umask 777 myfile c. chmod x=u ./myfile d. chmod x+u myfile e. chmod u+x ./myfile 35. In an empty directory, how many lines are in file foo after this command line: ls nosuchfile . .. 2>foo a. 4 b. 2 c. empty file (no data) d. 1 e. 3 36. What is true about this output from ls -il foo bar 23 -rwxr----- 3 root root 2 Jul 31 12:33 foo 24 -rwxr----- 3 root root 2 Jul 31 12:33 bar a. this output is not possible b. foo and bar are two of three names for this file c. foo and bar are names for the same file d. foo and bar each have two names (four names total) e. foo and bar are names for different files 37. What is the correct syntax to redirect both standard output and standard error into the same output file? a. command 2>out >out b. command 2>1 >out c. command >out 2>1 d. command 2>&1 >out e. command >out 2>&1 38. If /bin/bat is a program that outputs foo and /usr/bin/bat is a program that outputs hi what is the output on your screen of this shell command sequence: PATH=/usr:/usr/bin:/bin ; bat a. foo followed by hi b. bash: bat: command not found c. hi followed by foo d. hi e. foo 39. Which of the following PATH statements makes the most sense? a. PATH=/bin:/bin/cat:/usr/bin b. PATH=/usr:/bin:/usr/bin:/etc c. PATH=/bin/ls:/etc:/usr/bin d. PATH=/bin/sh:/usr/bin:/etc:/bin e. PATH=/bin:/usr/bin:/etc/passwd 40. If a=aaa and b=bbb then what is the output on your screen of the following command sequence: if $a = $b ; then echo $a ; fi a. test: aaa: integer expression expected b. no output c. aaa d. test: $a: integer expression expected e. bash: aaa: command not found 41. What is the output on your screen of this command sequence: true && echo Hello There $? a. Hello There ? b. Hello There ? c. no output d. Hello There 1 e. Hello There 0 42. What is the output on your screen of the following sequence of commands: x=1 ; y=2 ; [ $x -ge $y ] ; echo $? a. test: $x: integer expression expected b. 0 c. the number 0 or 1 followed by another 0 or 1 on a new line d. 1 e. no output 43. In an empty directory, what appears on your screen after this command line? ls 1>/dev/null nosuchfile a. ls: nosuchfile: No such file or directory b. ls: 1>/dev/null nosuchfile: No such file or directory c. ls: /dev/null: No such file or directory d. no output e. nosuchfile 44. If a shell script named foo contains the line: if [ '$3' = "$2" ] ; then echo SAME ; fi then which of the following command lines will always produce SAME as output? a. ./foo 2 '$3' 1 b. ./foo $3 "$2" $1 c. ./foo '$1' "$3" $2 d. ./foo $1 '$2' $3 e. ./foo $1 $2 $3 45. Which correct command sequence below always outputs just the date only if the first argument is both not empty and a directory? a. if [ -s -a -d "$1" ]; then date ; fi b. if [ "-s $1" && "-d $1" ]; then date ; fi c. if [ "$1" -eq -f -a "$1" -eq -d ]; then date ; fi d. if [ -d "$1" -a -s "$1" ]; then date ; fi e. if [ -s && -d "$1" ]; then date ; fi 46. Which command line shows just the type and permissions of file foo? a. cat foo | ls -l | awk ' ' '\n' | head -1 b. ls -l foo | awk ' ' '\n' c. ls -l foo | tr ' ' '\n' | head -1 d. ls -l foo | awk ' ' '\n' | head -1 e. tr ' ' '\n' bar a. empty file (no data) b. 2 c. 4 d. 1 e. 3 49. What is the output on your screen of the following 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. * b. the file names 1 through 123 c. $glob d. the file names 1 through 123, surrounded by quotes e. "$glob" 50. What is the output on your screen of the following sequence of commands: x=cow ; y=dog ; touch $y ; test -n $y ; echo $? a. no output b. 0 c. test: $y: integer expression expected d. the number 0 or 1 followed by another 0 or 1 on a new line e. 1 51. What is in the file cow after this command line: echo a >b ; echo b >a ; mv b a >cow a. a b. no such file (nonexistent) c. nothing - empty file - no data d. a followed by b e. b 52. What can you do to get back (redo) the last command you typed to the bash (Linux) shell? a. Type [CONTROL]-[ALT]-[DEL] b. Use the "UpArrow" key. c. Type [ALT]-[F2] d. Type [CONTROL]-[BACKSPACE] e. Use the "PageUp" key. 53. What is the output on your screen of the following command sequence: a=1 ; b=2 ; test $a -ge $b ; echo $? a. no output b. 1 c. test: $a: integer expression expected d. 0 e. the number 1 or 0 followed by another 1 or 0 on a new line 54. In an empty directory, what is the shell output on your screen 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. $a e. .1* .2* 55. Which command line shows just the count of lines in the file? a. wc file | awk '{print #1}' b. wc file | awk '{print 1}' c. wc file | awk '[print #1]' d. wc file | awk '{print $1}' e. wc file | awk '[print $1]' 56. In an empty directory, what is the length of the longest file name (including extension) after this sequence of commands? date >sixsix ; cp sixsix no ; mv sixsix four ; gzip no a. 5 b. 2 c. 3 d. 6 e. 4 57. If a=ant and b=bat then what is the output on your screen of the following command sequence: [ $a = bat -o $b = bat ] ; echo $? a. no output b. test: $a: integer expression expected c. 0 d. the number 1 or 0 followed by another 1 or 0 on a new line e. 1 58. Which of these first lines will cause this executable file to be interpreted using the Bash shell? a. !#/bin/bash -u b. #!/bin/bash c. $!/bin/bash -u d. !/bin/bash e. #/bin/bash 59. Which of the following PATH statements makes the most sense? a. PATH=/bin:/bin/cat:/usr/bin b. PATH=/bin:/usr/bin:/etc/passwd c. PATH=/bin/sh:/usr/bin:/etc:/bin d. PATH=/bin/ls:/etc:/usr/bin e. PATH=/bin:/usr/bin:/etc 60. What is the possible output on your screen of this command line: echo wc >date ; sort date >date ; cat date a. 1 6 28 date b. Mon Sep 27 15:58:34 EDT 2004 c. 1 6 29 date d. wc e. no output on screen 61. How many arguments are passed to the command by the shell on this command line: bar" bar >out a. 2 b. 5 c. 3 d. 4 e. 6 62. What appears on your screen after this command line? echo hi >ls ; cat ls > wc a. hi b. no output on screen c. 1 1 3 d. ls e. 1 1 2 63. What is the output on your screen of the following command sequence: i=0 ; test $i = 00 ; echo $? a. 0 b. no output c. test: $i: integer expression expected d. the number 0 or 1 followed by another 0 or 1 on a new line e. 1 64. Which of these statements is true? a. The ls dir command looks up the directory argument dir in your $PATH. b. If /q is an empty directory, echo /q/.* produces an error message. c. Typing ./script and bash script always give identical results. d. If /p is an empty directory, ls /p/.* produces an error message. e. Either single or double quotes will stop shell GLOB (wildcard) patterns from expanding. 65. What is true about this output from ls -ild foo bar 96 -rwxr-xr-x 2 root root 3 Jan 24 01:03 foo 96 -rwxr-xr-x 3 root root 3 Jan 24 01:03 bar a. foo and bar are two of five names for this file b. foo and bar are names for different files c. foo and bar each have three names (six names total) d. foo and bar are names for the same file e. this output is not possible 66. Which command line below outputs only lines 10-15 of the 16-line file named cow? a. head -15 | tail -6 cow b. head -16 cow | tail -5 cow c. tail -16 cow | head -10 d. head -15 cow | tail -6 e. tail -10 cow | head -6 cow 67. Which command sequence correctly searches for foo and then prints the date if it is found inside the file bar? a. if test foo bar ; then date ; fi b. if [ test foo bar ] ; then date ; fi c. if test foo = bar ; then date ; fi d. if [ grep foo bar ] ; then date ; fi e. if grep 3 ) ; then echo OK ; fi b. if ( ! 4 < 3 ) ; then echo OK ; fi c. if [ 4 > 3 ] ; then echo OK ; fi d. if [ ! 4 <= 3 ] ; then echo OK ; fi e. if [ 4 -gt 3 ] ; then echo OK ; fi 70. 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 on your screen from this line? a. "3 b. 1 2 3 c. 3 4 d. $3 e. 2 3 4 71. What is the output on your screen if a user signals an end-of-file from the keyboard during this command sequence? read input ; echo $? a. 1 b. an error message c. 0 d. $? e. no output on screen 72. Which line below is most likely to be the beginning of an error message? a. echo 1>&2 "... " b. echo 2>$1 "... " c. echo 1<&2 "... " d. echo 2>&1 "... " e. echo 2<$1 "... " 73. If a 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 "bar" 'bar' b. ./foo '$2' bar c. ./foo bar bar d. ./foo "$1" '$2' e. ./foo $2 $2 74. What is the output on your screen of the following sequence of commands: cd /etc && echo "in $(pwd)" a. in /etc b. bash: cd: /etc: No such file or directory c. no output d. in $(pwd) e. in 0pwd) 75. What is the output on your screen of the following command sequence: a=sky ; touch $a ; test -z $a ; echo $? a. no output b. sky c. 0 d. test: $a: integer expression expected e. 1 76. In an empty directory, what is the length of the longest file name (including extension) after this sequence of commands? date >four ; cp four five5 ; mv five5 hi ; bzip2 hi a. 7 b. 3 c. 6 d. 5 e. 4 77. What is the output on your screen of this two-command sequence if run in a directory containing 888 files with names that are all the numbers from 1 to 888 inclusive: cow="*" ; echo '$cow' a. the file names 1 through 888, surrounded by quotes b. '$cow' c. the file names 1 through 888 d. * e. $cow 78. Given the following command line: read xx yy zz which user keyboard input line below will assign the text 22 to the shell variable named yy? a. 11 22 33 b. 11;22;33 c. 11:22:33 d. 11,22,33 e. xx=11 yy=22 zz=33 79. In a directory containing one file named dog, what appears on your screen after this command line? 2>/dev/null ls nosuchfile a. nosuchfile b. ls: nosuchfile: No such file or directory c. dog d. no output on screen e. bash: 2>/dev/null: command not found 80. What is the output on your screen of this two-command sequence if run in a directory containing 765 files with names that are all the numbers from 1 to 765 inclusive: foo="*" ; echo $foo a. the file names 1 through 765 b. an asterisk ('*') and the file names 1 through 765 c. all the file names that start with an asterisk ('*') d. $foo e. * 81. If bar is a script containing the line TERM=vt100 ; export TERM, what is the output on your screen of the following command sequence: TERM=linux ; ./bar ; echo $TERM a. vt100 b. $TERM c. bar d. linux e. TERM 82. What is the output on your screen of this sequence of three shell commands: umask 162 ; touch newfile ; ls -l newfile a. ---xrw--w- 1 me me 0 Oct 1 01:12 newfile b. -rw----r-- 1 me me 0 Oct 1 01:12 newfile c. -rw---x-w- 1 me me 0 Oct 1 01:12 newfile d. -rw---xr-x 1 me me 0 Oct 1 01:12 newfile e. ----rw--w- 1 me me 0 Oct 1 01:12 newfile 83. In response to the following command line: read var1 var2 var3 which user keyboard input line below will assign the text three to the shell variable named var3? a. one,two,three b. $var1="one" $var2="two" $var3="three" c. one two three d. var1=one var2=two var3=three e. one:two:three 84. Which line below passes three separate arguments to the sort command when placed inside a shell script named foo invoked by the command line: ./foo 111 222 333 a. sort "$1 $2 $3" b. sort "$*" c. sort "$@" d. sort "$? $? $?" e. sort "$#" 85. What is the shell output on your screen of this two-command sequence: cd /home/alleni && echo "In $(pwd)" a. "In $(pwd)" b. In $(pwd) c. no output d. In 0pwd) e. In /home/alleni 86. What is true about this output from ls -il foo bar 35 -rw-rw-r-- 2 bin bin 3 Jan 24 01:03 foo 36 -rw-rw-r-- 2 bin bin 3 Jan 24 01:03 bar a. foo and bar each have two names (four names total) b. foo and bar each have three names (six names total) c. foo and bar are names for the same file d. foo and bar are two of three names for this file e. this output is not possible 87. What is the output on your screen of the following sequence of commands: x=0 ; test $x ; echo $? a. test: $x: integer expression expected b. 0 c. 1 d. no output e. the number 0 or 1 followed by another 0 or 1 on a new line 88. How many arguments and options are there to the command: wc wc a. Four arguments, only one of which is an option argument with two options. b. One argument: a single option argument with two option letters. c. Three arguments, each of which is a pathname argument. d. Three arguments: two file names and one option argument with two options. e. Two arguments: an input file and an option argument with two options. 89. Which command line tells you the recursive count of all pathnames under the current directory and all subdirectories? a. find | wc b. wc * c. wc "$PATH" d. wc . e. ls | wc 90. How can you ask the bash (Linux) shell to complete commands or file names for you? a. Type the first part of the command or file name and press the [ALT]-[F1] key. b. Type the first part of the command or file name and press the [ALT] key. c. Type the first part of the command or file name and press the [TAB] key. d. Type the first part of the command or file name and press the [CTRL]-[C] key. e. Type the first part of the command or file name and press the [CTRL]-[D] key. 91. What is the output on your screen of the following sequence of commands: x=0 ; y=1 ; touch $x ; test ! -n $x ; echo $? a. test: $x: integer expression expected b. the number 1 or 0 followed by another 1 or 0 on a new line c. 1 d. no output e. 0 92. What is the output on your screen of the following sequence of commands: a=9 ; b=9 ; [ $a -le $b ] ; echo $? a. 1 b. no output c. the number 1 or 0 followed by another 1 or 0 on a new line d. test: $a: integer expression expected e. 0 93. If bar is an executable script containing the line dog=bat then what is the output on your screen of this sequence of three commands: dog=cat ; ./bar ; echo "the '$dog' ate" a. the $dog ate b. the 'cat' ate c. the 'dog' ate d. the '$dog' ate e. the 'bat' ate 94. What appears on your screen after this sequence of commands: echo 1 >x ; cp x y ; echo 2 >>y ; sort x >y ; cat y a. 2 followed by 1 b. 1 followed by 2 c. 2 d. empty file - no output on the screen e. 1 95. If foo is a file containing the first column of the output of the last command, which command line shows the most frequent login? a. sort foo | uniq -c | sort -nr | head -1 b. cat sort foo | uniq -c | sort -nr | head -1 c. sort foo > uniq -c ; sort -nr uniq | head -1 d. sort | uniq -c | sort -nr | head -1 foo e. uniq -c foo | sort -nr | head -1 96. What is the link count of directory d after this set of successful commands? mkdir d ; cd d ; touch f ; ln f x ; ln f y a. 5 b. 1 c. 3 d. 2 e. 4 97. What is true about this output from ls -il foo bar 72 -rwxrwxrwx 2 bin bin 3 Oct 30 09:23 foo 72 -r--r--r-- 2 bin bin 3 Oct 30 09:23 bar a. foo and bar are two of three names for this file b. this output is not possible c. foo and bar are names for different files d. foo and bar each have two names (four names total) e. foo and bar are names for the same file 98. 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. 1 b. 3 c. 4 d. 2 e. 5 99. Which command tells you the count of lines in the bash manual page? a. which bash | wc b. apropos bash | wc c. man bash | wc d. whereis bash | wc e. man bash > wc ; cat wc 100. Which line below puts the count of the number of lines in the password file into the variable foo? a. foo=$( wc /etc/passwd | awk echo $1 ) b. foo=$( wc -l /etc/passwd | awk "print $1" ) c. foo=$( cat -c /etc/passwd ) d. foo=$( awk -F: /etc/passwd | wc -l ) e. foo=$( wc -l wc ; wc wc >hi ; cat hi a. hi b. 1 1 3 wc c. 1 1 2 wc d. 0 0 0 wc e. no output 104. Which command sequence correctly searches for the chars and then prints OK if it is found inside the password file? a. grep chars >/etc/passwd || echo OK b. grep chars /etc/passwd && echo OK d. grep chars /etc/passwd || echo OK e. grep chars mail idallen@idallen.ca d. mkdir foo bar ; ln foo xxx e. date >foo ; cp foo/. bar 128. Which command sequence correctly searches for the chars and then prints OK if it is found inside the password file? a. if grep chars /etc/passwd ; then echo OK ; fi b. if [ test chars /etc/passwd ] ; then echo OK ; fi c. if test chars = /etc/passwd ; then echo OK ; fi d. if [ grep chars /etc/passwd ] ; then echo OK ; fi e. if test chars /etc/passwd ; then echo OK ; fi 129. What is the output on your screen of the following command sequence: x=1 ; y=2 ; test $x -le $y ; echo $? a. test: $x: integer expression expected b. 1 c. the number 0 or 1 followed by another 0 or 1 on a new line d. no output e. 0 130. If variable mt might contain nothing (a null value - defined but empty), which 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 131. What is the output on your screen of the following command sequence: date='Friday March 12' ; test date = date a. no output b. 1 c. Fri Mar 12 10:20:39 EST 2004 d. test: too many arguments e. 0 132. What appears on your screen after this sequence of commands: echo 1 >x ; ln x y ; echo 2 >>y ; head -1 x >y ; cat y a. empty file - no output on the screen b. 1 followed by 2 c. 2 followed by 1 d. 1 e. 2 133. If /bin/foo is a program that outputs mom and /usr/bin/foo is a program that outputs dad what is the output on your screen of this shell command sequence: PATH=/bin/foo:/usr/bin/foo:/usr ; foo a. dad b. bash: foo: command not found c. mom followed by dad d. dad followed by mom e. mom 134. What is the shell output on your screen of this two-command sequence: cd /home/alleni || echo "In $(pwd)" a. "In $(pwd)" b. In /home/alleni c. In $(pwd) d. no output e. In 0pwd) 135. In an empty directory, what appears on your screen after this command line? ls 2>/dev/null nosuchfile a. nosuchfile b. ls: 2>/dev/null nosuchfile: No such file or directory c. ls: /dev/null: No such file or directory d. no output e. ls: nosuchfile: No such file or directory 136. What is true about this output from ls -il foo bar 15 -r-x-----x 2 bin bin 3 Oct 30 09:23 foo 15 -r-x-----x 2 bin bin 3 Oct 30 09:23 bar a. this output is not possible b. foo and bar are names for the same file c. foo and bar are names for different files d. foo and bar are two of three names for this file e. foo and bar each have three names (six names total) 137. Which command sequence correctly compares the numbers and prints OK? a. if [ 1 -lt 2 ] ; then echo OK ; fi b. if ( 1 let 2 ) ; then echo OK ; fi c. if ( let 2 > 1 ) ; then echo OK ; fi d. if [ ! 2 < 1 ] ; then echo OK ; fi e. if [ 2 > 1 ] ; then echo OK ; fi 138. If the file bat contained the word foo, what would be the output on your screen of this two command sequence: PATH=/bin/ls:/bin/who:/etc/passwd ; /bin/ls bat a. /bin/ls: bat: No such file or directory b. no output c. bash: /bin/ls: command not found d. bat e. foo 139. What is the output on your screen of the following sequence of commands: i=00 ; [ $i = 0 ] ; echo $? a. test: $i: integer expression expected b. the number 0 or 1 followed by another 0 or 1 on a new line c. no output d. 1 e. 0 140. In an empty directory, what is the output on your screen of these commands: touch uu .u uv .v uw ; a="*u *v" ; echo "$a" a. $a b. uu .u uv .v c. uu uv d. *u *v e. u* v* 141. If foo were a file of text containing 50 different lines, what would be the output on your screen of this exact command line: diff foo foo a. several lines, which are the lines that are different between the two files b. the contents of file foo would be displayed c. an error message because diff doesn't allow the same file name twice d. an error message because diff only allows one file name e. no output 142. What is the output on your screen of this two command sequence: PATH=/bin/cat:/bin/sh:/bin/ls ; ls nosuchfile a. ls: nosuchfile: No such file or directory b. bash: ls: command not found c. ls: /bin/ls: command not found d. bash: /bin/sh: No such file or directory e. bash: /bin/ls: command not found 143. A shell script named bar is executed as follows: ./bar "a b" "c d e" f Inside the script is the line: echo "$2" What is the output on your screen from this line? a. a b b. b c. b" d. $2 e. c d e 144. What is the output on your screen of the following command sequence: echo wc >wc ; wc wc >wc ; head wc a. 1 1 3 wc b. no output c. wc d. 1 1 2 wc e. 0 0 0 wc 145. If foo is an executable script containing the line: PATH=/bin ; export PATH what is the output on your screen of the following sequence of commands: PATH=/etc ; ./foo ; echo "$PATH" a. /etc:/bin b. /etc c. foo d. $PATH e. /bin 146. Which command line below allows programs in the current directory to execute without preceding the names with ./? a. PATH=.:/bin:$HOME b. PATH=./$HOME:./bin c. PATH=/bin/.:$HOME/. d. $PATH=./bin:./$HOME e. $PATH=$HOME:.:/usr/bin 147. Which of the following bash PATH statements makes the most sense? a. PATH=/bin:/bin/cat:/usr/bin b. PATH=/bin:/usr/bin:/etc/passwd c. PATH=/bin/ls:/etc:/usr/bin d. PATH=/bin:/usr/bin:/etc e. PATH=/bin/sh:/usr/bin:/etc:/bin 148. In a directory containing one file named dog, what appears on your screen after this command line? 1>/dev/null ls * a. dog b. ls: *: No such file or directory c. bash: 1>/dev/null: command not found d. * e. no output on screen 149. If the file bat contained the word foo, what would be the output on your screen of this two command sequence: PATH=/bin/cat:/bin/who:/bin/ls ; cat bat a. cat: bat: No such file or directory b. bat c. bash: cat: command not found d. foo e. no output on screen 150. What is the link count of file f after this set of successful commands? rm f ; touch f ; cp f x ln f a ; ln x y ; ln a z ; ln x b a. 6 b. 3 c. 4 d. 5 e. 2 151. What is the output on your screen of the following command sequence: f=1 ; touch f ; test ! -z $f ; echo $? a. 0 b. 1 c. no output d. the number 1 or 0 followed by another 1 or 0 on a new line e. test: $f: integer expression expected 152. If a=1 and b=1, which command sequence correctly compares the two numbers as equal and prints OK? a. if test a -eq b ; then echo OK ; fi b. if ( a == b ) ; then echo OK ; fi c. if [ a = b ] ; then echo OK ; fi d. if [ $a -eq $b ] ; then echo OK ; fi e. if [ $a==$b ] ; then echo OK ; fi 153. What minimal permissions must you have on a directory to be able to execute successfully the command ls . from inside the directory? a. -wx b. rw- c. r-x d. r-- e. --x 154. Which command line shows the file in /bin with the largest checksum? a. ls /bin/* | sum | sort -nr | head -1 b. cat /bin/* | sum | sort -nr | head -1 c. sum /bin/* | sort -nr | head -1 d. sum /bin | sort -nr | head -1 e. cat /bin | sum | sort -nr | head -1 155. Which command line shows the current date? a. date | bash b. bash date c. echo date | bash d. bash >date ; cat date e. bash bar bar bar a. 6 b. 3 c. 2 d. 4 e. 5 157. What is the output on your screen if a user signals an end-of-file from the keyboard during this command sequence? read input && echo $? a. an error message b. 1 c. no output on screen d. 0 e. $? Answer Key - CST8129 - Ian Allen - Fall 2005 - CST8129 Practice Test 1. b 57. c 2. a 58. b 3. a 59. e 4. a 60. e 5. e 61. a 6. b 62. b 7. c 63. e 8. c 64. e 9. a 65. e 10. c 66. d 11. c 67. e 12. b 68. c 13. a 69. e 14. d 70. c 15. a 71. a 16. d 72. a 17. b 73. b 18. a 74. a 19. b 75. e 20. b 76. c 21. e 77. e 22. d 78. a 23. d 79. d 24. a 80. a 25. a 81. d 26. e 82. b 27. d 83. c 28. e 84. c 29. c 85. e 30. a 86. a 31. e 87. b 32. a 88. b 33. d 89. a 34. e 90. c 35. d 91. c 36. e 92. e 37. e 93. b 38. d 94. e 39. b 95. a 40. e 96. d 41. e 97. b 42. d 98. c 43. a 99. c 44. a 100. e 45. d 101. d 46. c 102. e 47. d 103. b 48. d 104. e 49. a 105. c 50. b 106. b 51. c 107. c 52. b 108. c 53. b 109. d 54. d 110. d 55. d 111. a 56. a 112. a 113. b 114. d 115. b 116. a 117. a 118. a 119. e 120. e 121. a 122. d 123. a 124. a 125. a 126. e 127. b 128. a 129. e 130. d 131. a 132. a 133. b 134. d 135. d 136. b 137. a 138. d 139. d 140. d 141. e 142. b 143. e 144. e 145. b 146. a 147. d 148. e 149. c 150. b 151. a 152. d 153. c 154. c 155. c 156. e 157. c Count of a: 39 25% Count of b: 28 18% Count of c: 25 16% Count of d: 31 20% Count of e: 34 22% With 5 choices: 157 Macro .cmd split with indent: 69