Practice Test #3 Questions 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 - 103 Questions This is a practice test containing many practice questions. The real test will contain some questions similar to these. 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. (Office use only: 22 7 50 10 76 65 98 13 27 83 102 4 64 54 41 70 57 55 38 1 77 39 24 16 81 45 92 74 30 90 20 42 36 100 103 15 46 85 6 40 95 51 31 78 63 26 79 52 73 47 97 35 37 43 72 89 8 33 88 75 32 3 66 25 53 93 61 29 11 59 49 87 9 84 96 21 86 19 12 94 101 28 99 14 71 58 48 62 56 44 82 60 68 5 18 69 17 67 91 34 2 80 23) 1. Which command line below allows programs in the current directory to execute without preceding the names with ./? a. PATH = /bin:$HOME:. b. PATH=/bin:$HOME:. c. $PATH=/bin:./$HOME d. $PATH=.:$HOME:/bin e. PATH = ./$HOME:/bin 2. If /etc/passwd is a file name, which of the following pathnames always leads to the same file? a. /etc/passwd/../.. b. /etc/../../passwd c. /etc/passwd/./. d. ././etc/passwd e. /./../etc/./passwd 3. In an empty directory, what is the length of the longest file name created by the following two-command sequence: var='1 12 123 1234 12345' ; touch '$var' a. 1 character b. 2 characters c. 4 characters d. 3 characters e. 13 characters 4. 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 on your screen of this command: cat foo foo | cat | tail -5 | head -1 a. 8 b. 5 c. 7 d. 9 e. 6 5. Which 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 && -d "$1" ]; then date ; fi c. if [ "$1" -eq -f -a "$1" -eq -d ]; then date ; fi d. if [ "-s $1" && "-d $1" ]; then date ; fi e. if [ -d "$1" -a -s "$1" ]; then date ; fi 6. How many arguments and options are there to the command: sort -r abc ; ls >abc abc ; wc abc a. 1 1 2 abc b. 1 1 4 abc c. no output d. 0 0 0 abc e. 1 1 3 abc 12. Which command sequence correctly compares the two numbers and prints OK? a. if ( ! 4 < 3 ) ; then echo OK ; fi b. if [ ! 4 <= 3 ] ; then echo OK ; fi c. if [ 4 > 3 ] ; then echo OK ; fi d. if ( let 4 > 3 ) ; then echo OK ; fi e. if [ 4 -gt 3 ] ; then echo OK ; fi 13. 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 bar 'bar' c. ./foo $1 $1 d. ./foo 1 "$1" e. ./foo bar '$1' 14. Given my directory dir and my file dir/foo owned by me, which permissions allow me to change or create new content (data) in the file dir/foo but not delete the file? a. Permissions 500 on directory dir and 600 on file dir/foo. b. Permissions 600 on directory dir and 700 on file dir/foo. c. Permissions 200 on directory dir and 200 on file dir/foo. d. Permissions 400 on directory dir and 400 on file dir/foo. e. Permissions 100 on directory dir and 100 on file dir/foo. 15. 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. 2 3 4 d. "3 e. 3 4 16. What is the output on your screen of this sequence of three shell commands: umask 674 ; touch newfile ; ls -l newfile a. --w--wxr-x 1 me me 0 Feb 20 07:55 newfile b. -rw-rw-r-- 1 me me 0 Feb 20 07:55 newfile c. --------w- 1 me me 0 Feb 20 07:55 newfile d. -rw-rwxr-- 1 me me 0 Feb 20 07:55 newfile e. ---x----wx 1 me me 0 Feb 20 07:55 newfile 17. If the file pig contained the word foo, what would be the output on your screen 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. pig c. bash: /bin/ls: command not found d. foo e. no output 18. What is in the file named file after this command sequence: echo a >x ; echo b >>x ; mv x y >file a. no such file (nonexistent file) b. a followed by b c. nothing - file is empty - no data d. b e. a 19. What is the output on your screen of the following sequence of commands: wc='one two' ; test wc = wc a. 1 b. 1 2 8 wc c. test: too many arguments d. 0 e. no output 20. 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 21. Which command sequence below always outputs just the date only if the first argument is either a file or a directory? a. if [ -f "$1" -o -d "$1" ]; then date ; fi b. if [ "$1" -eq -f -o "$1" -eq -d ]; then date ; fi c. if [ "-f $1" || "-d $1" ]; then date ; fi d. if [ -f -o -d "$1" ]; then date ; fi e. if [ -f || -d "$1" ]; then date ; fi 22. What is the output on your screen of this command sequence: echo dog >one ; echo cow | head -2 one a. cow b. dog c. dog followed by cow d. an error message e. cow followed by dog 23. Which of the command lines below can generate a non-empty file? a. sort -r /a/b >/a/b b. grep -v /a/b /a/b >/a/b c. ls /a/b >/a/b d. tr abc ABC /a/b e. tail -5 /a/b >/a/b 24. In an empty directory, what is the shell output of these three commands: touch xx .x xy .y xz ; a='x* y*' ; echo "$a" a. xx xy b. *x *y c. $a d. xx xy xz y* e. x* y* 25. What is the output on your screen of this command sequence: false && echo "hello there $?" a. hello there 1 b. hello there 1 c. hello there 0 d. no output e. hello there 0 26. What is the shell output of this two-command sequence: cd /home/alleni || echo "In $(pwd)" a. In $(pwd) b. no output c. "In $(pwd)" d. In 0pwd) e. In /home/alleni 27. Which of the following PATH statements makes the most sense? a. PATH=/bin:/bin/cat:/usr/bin b. PATH=/bin:/usr/bin:/etc c. PATH=/bin:/usr/bin:/etc/passwd d. PATH=/bin/ls:/etc:/usr/bin e. PATH=/bin/sh:/usr/bin:/etc:/bin 28. How many arguments are passed to the command by the shell on this command line: bar bar bar a. 6 b. 5 c. 3 d. 4 e. 2 29. What is the output on your screen of the following sequence of commands: a=1 ; b=2 ; test $a -ge $b ; echo $? a. the number 1 or 0 followed by another 1 or 0 on a new line b. 0 c. no output d. 1 e. test: $a: integer expression expected 30. 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. umask 777 myfile d. umask 111 myfile e. chmod x=u ./myfile 31. If a=xxx and b=yyy then what is the output on your screen of the following sequence of bash commands: if $a = $b ; then echo $a ; fi a. test: xxx: integer expression expected b. xxx c. test: $a: integer expression expected d. no output e. bash: xxx: command not found 32. Which of these statements is true? a. If /x is an empty directory, sort /x/* produces an error message. b. The cat food command looks up the file name argument food in your $PATH. c. Typing ./script and bash script always give identical results. d. Only single quotes are strong enough to stop shell glob (wildcard) patterns from expanding. e. If /y is an empty directory, echo /y/* produces an error message. 33. What is the output on your screen of the following sequence of commands: echo wc >wc ; wc wc >wc ; cat wc a. 1 1 2 wc b. 1 1 3 wc c. 0 0 0 wc d. no output e. wc 34. Which command line displays the contents of the Unix passwd file one page at a time? a. /etc/passwd | less b. /etc/passwd >less c. less | /etc/passwd d. cat /etc/passwd >less e. less /c ; cat /a >>/b ; sort /c /b /a >/c a. no lines (empty file) b. 120 c. 80 d. 70 e. 50 39. If x=5 and y=5, which command sequence correctly compares the two numbers as equal and prints OK? a. if [ x = y ] ; then echo OK ; fi b. if test x -eq y ; then echo OK ; fi c. if [ $x==$y ] ; then echo OK ; fi d. if test $x -eq $y ; then echo OK ; fi e. if ( x == y ) ; then echo OK ; fi 40. If dog=12 and cat=99 then which of the following command lines outputs only the word hi (and nothing else)? a. [dog -ne cat] || echo hi b. [!dog = cat] && echo hi c. [ dog -ne cat ] && echo hi d. [ dog = dog ] && echo hi e. [dog!=dog] || echo hi 41. Which line below puts the count of the number of lines in the password file into the variable foo? a. foo=$( cat -c /etc/passwd ) b. foo=[ cat -l /etc/passwd ] c. foo=[ wc /etc/passwd | echo $1 ] d. foo=$( wc -l foo file bar haven a. The command foo sees only two arguments b. Error: The command name is missing from the command line. c. The command foo sees three arguments. d. The command file sees two arguments. e. The command file sees three arguments. 50. What is the output of this two-command sequence: cd /bin && echo "echo $(pwd)" a. echo $(pwd) b. echo 0pwd) c. no output d. /bin e. echo /bin 51. In an empty directory, what is the output on your screen of this three-command sequence: touch aa .a ab .b .c ; x='.a* .b*' ; echo '$x' a. .a .b b. .a* .b* c. aa .a ab .b d. '.a* .b*' e. $x 52. What is the output on your screen of the following sequence of commands: i=0 ; test $i = 00 ; echo $? a. 0 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. no output 53. What is the output on your screen of the following sequence of commands: echo hi >wc ; wc wc >hi ; cat hi a. 1 1 2 wc b. hi c. no output d. 0 0 0 wc e. 1 1 3 wc 54. Which of these statements is true? a. If /q is an empty directory, echo /q/.* produces an error message. b. Typing ./script and bash script always give identical results. c. The ls dir command looks up the directory argument dir in your $PATH. d. Either single or double quotes will stop shell glob (wildcard) patterns from expanding. e. If /p is an empty directory, ls /p/.* produces an error message. 55. What is the output on your screen of this two command sequence: PATH=/bin/ls:/bin/cat:/bin/sh ; cat nosuchfile a. bash: cat: command not found b. bash: /bin/sh: No such file or directory c. ls: /bin/cat: command not found d. bash: /bin/ls: command not found e. cat: nosuchfile: No such file or directory 56. 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/\?? c. rm dir/?? d. rm dir/1* e. rm dir/?1 57. If /etc/passwd is a file name, which of the following pathnames always leads to the same file? a. /etc/passwd/../.. b. /etc/../../passwd c. /etc/passwd/. d. ./etc/passwd e. /../etc/passwd 58. What is the output on your screen of the following sequence of commands: x=0 ; test $x ; echo $? a. the number 0 or 1 followed by another 0 or 1 on a new line b. 0 c. no output d. 1 e. test: $x: integer expression expected 59. If directory /dir contains these three four-character file names: .123, .124, .???, then what is the output on your screen of the following command line: echo /dir/???? a. no output b. echo: /dir/????: No such file or directory c. /dir/???? d. /dir/.123 /dir/.124 e. /dir/.123 /dir/.124 /dir/.??? 60. How many arguments are passed to the command by the shell on this command line: bat bat bat a. 5 b. 6 c. 2 d. 3 e. 4 61. What is the output on your screen of the following sequence of commands: x=cow ; y=dog ; touch $x ; test -z $x ; echo $? a. 1 b. the number 0 or 1 followed by another 0 or 1 on a new line c. test: $x: integer expression expected d. 0 e. no output 62. 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 e. grep chars /etc/passwd || echo OK 63. What is the output on your screen of the following sequence of commands: cd /etc && echo "in $(pwd)" a. in 0pwd) b. in $(pwd) c. in /etc d. no output e. bash: cd: /etc: No such file or directory 64. What is the output on your screen of the following sequence of commands: x=1 ; touch x ; test ! -z $x ; echo $? a. 1 b. test: $x: integer expression expected c. the number 1 or 0 followed by another 1 or 0 on a new line d. 0 e. no output 65. Given my directory dir and my file dir/foo owned by me, which permissions allow me to delete the file dir/foo from the directory, but not change the content (data) in the file? a. Permissions 500 on directory dir and 400 on file dir/foo. b. Permissions 300 on directory dir and 500 on file dir/foo. c. Permissions 300 on directory dir and 300 on file dir/foo. d. Permissions 100 on directory dir and 100 on file dir/foo. e. Permissions 100 on directory dir and 200 on file dir/foo. 66. Which of the following VI/VIM key sequences will move the entire line on which the cursor resides to after the line that follows it (i.e. it would move line 5 to be line 6 and line 6 would become line 5)? a. DDP b. :dp c. ddP d. DDp e. ddp 67. If bar is an executable script containing the line foo=dog then what is the output on your screen of this sequence of three commands: foo=cat ; ./bar ; echo "the '$foo' ate" a. the $foo ate b. the 'foo' ate c. the '$foo' ate d. the 'cat' ate e. the 'dog' ate 68. What is the output on your screen of the following sequence of commands: x=1 ; y=2 ; test $x -le $y ; echo $? a. test: $x: integer expression expected b. no output c. the number 0 or 1 followed by another 0 or 1 on a new line d. 1 e. 0 69. 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 on your screen of this command: cat foo foo | sort -r | head -5 | tail -1 a. 7 b. 9 c. 8 d. 6 e. 5 70. 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. '$cow' b. * c. the file names 1 through 888 d. the file names 1 through 888, surrounded by quotes e. $cow 71. In an empty directory, what is the length of the longest file name created by the following two-command sequence: ok='1 12 123 1234' ; touch '$ok' a. 1 character b. 3 characters c. 13 characters d. 4 characters e. 2 characters 72. If x=pig and y=dog then what is the output on your screen of the following sequence of commands: if $x = $y ; then echo $y ; fi a. no output b. test: pig: integer expression expected c. dog d. bash: pig: command not found e. test: $x: integer expression expected 73. 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 on your screen of this command: cat foo foo | cat | tail -4 | head -1 a. 7 b. 8 c. 5 d. 9 e. 6 74. What is the output on your screen of the following sequence of commands: false && echo "foo bar $?" a. foo bar 1 b. foo bar 1 c. foo bar 0 d. foo bar 0 e. no output 75. Which of the following shell command lines displays only the names in the current directory that are exactly three numeric digits long? a. echo '0-9'0-9'0-9' b. echo [0-9][0-9][0-9] c. echo '[0-9]''[0-9]''[0-9]' d. echo ??? e. echo [1-3][1-3][1-3] 76. If my current working directory is /home, and my home directory is /home/me, which of the of the following commands copies the Unix password file into my home directory under the name foo? a. cp ../../etc/passwd /me/foo b. cp me/../../etc/passwd me/foo c. cp ./me/../etc/passwd ../home/me/foo d. cp ../etc/passwd ../me/foo e. cp ../home/me/../etc/passwd ./me/./foo 77. 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. 160 b. 100 c. 40 d. 200 e. 60 78. If a=cow and b=dog then what is the output on your screen of the following sequence of bash commands: if $a = $b ; then echo $a ; fi a. test: $a: integer expression expected b. bash: cow: command not found c. test: cow: integer expression expected d. cow e. no output 79. 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 on your screen of this command: cat foo foo | sort -r | head -4 | tail -1 a. 7 b. 9 c. 8 d. 5 e. 6 80. Which line below is most likely to be the beginning of an error message? a. echo 2<$1 "... " b. echo 2>&1 "... " c. echo 2>$1 "... " d. echo 1>&2 "... " e. echo 1<&2 "... " 81. 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 "$@" b. sort "$*" c. sort "$? $? $?" d. sort "$1 $2 $3" e. sort "$#" 82. What is the output on your screen of the following sequence of commands: x=cow ; y=dog ; test -z $x ; echo $? a. the number 0 or 1 followed by another 0 or 1 on a new line b. 1 c. 0 d. test: $x: integer expression expected e. no output 83. 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. r-- c. --x d. r-x e. rw- 84. 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 -eq "" ] ; then echo OK ; fi b. if [ "$mt" = "" ] ; 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 85. What is the output on your screen of this sequence of three shell commands: umask 762 ; touch newfile ; ls -l newfile a. --------wx 1 me me 0 Oct 1 1:12 newfile b. ------xr-x 1 me me 0 Oct 1 1:12 newfile c. -rwxrw--w- 1 me me 0 Oct 1 1:12 newfile d. -rw-rw--w- 1 me me 0 Oct 1 1:12 newfile e. -------r-- 1 me me 0 Oct 1 1:12 newfile 86. What is the output on your screen 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: bat="*" ; echo "$bat" a. the file names 1 through 123, surrounded by quotes b. "$bat" c. $bat d. * e. the file names 1 through 123 87. In an empty directory, what is the length of the longest file name created by the following two-command sequence: x='1 12 123 1234' ; touch '$x' a. 1 character b. 4 characters c. 13 characters d. 2 characters e. 3 characters 88. If /bin/pig is a program that outputs hi and /usr/bin/pig is a program that outputs foo what is the output on your screen of this shell command sequence: PATH=/etc:/usr/bin:/bin ; pig a. foo followed by hi b. foo c. bash: pig: command not found d. hi e. hi followed by mom 89. Which command line below does not show any lines from inside the file dog? a. more dog b. head dog c. ls dog d. tail dog e. less dog 90. What is the shell output of this two-command sequence: cd /home/alleni && echo "In $(pwd)" a. "In $(pwd)" b. In /home/alleni c. In $(pwd) d. In 0pwd) e. no output 91. 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. xx=11 yy=22 zz=33 c. 11 22 33 d. 11,22,33 e. 11:22:33 92. 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. all the file names that start with an asterisk ('*') b. an asterisk ('*') and the file names 1 through 765 c. * d. $foo e. the file names 1 through 765 93. What is the output on your screen of this sequence of three shell commands: umask 547 ; mkdir newdir ; ls -ld newdir a. d-w--wx--- 1 me me 0 Feb 20 07:55 newdir b. d-w--w---- 1 me me 0 Feb 20 07:55 newdir c. dr--r--rw- 1 me me 0 Feb 20 07:55 newdir d. dr-xr--rwx 1 me me 0 Feb 20 07:55 newdir e. d-w--wxrwx 1 me me 0 Feb 20 07:55 newdir 94. If a=1 and b=1, which command sequence correctly compares the two numbers as equal and prints OK? a. if [ a = 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 -eq $b ] ; then echo OK ; fi e. if [ $a==$b ] ; then echo OK ; fi 95. If a=cow and b=dog then what is the output on your screen of the following sequence of commands: [ $a = cow -a $b = cow ] ; echo $? a. 0 b. no output c. test: $a: integer expression expected d. the number 1 or 0 followed by another 1 or 0 on a new line e. 1 96. What is the output on your screen of this sequence of three shell commands: umask 457 ; mkdir newdir ; ls -ld newdir a. d-wx-w-rwx 2 me me 512 Oct 1 1:12 newdir b. d-wx-w---- 2 me me 512 Oct 1 1:12 newdir c. d-w--w---- 2 me me 512 Oct 1 1:12 newdir d. dr-xr-xrwx 2 me me 512 Oct 1 1:12 newdir e. dr--r-xrwx 2 me me 512 Oct 1 1:12 newdir 97. If a=cow and b=dog then what is the output on your screen of the following sequence of commands: [ $a = dog -o $b = cow ] ; echo $? a. no output b. 0 c. the number 1 or 0 followed by another 1 or 0 on a new line d. 1 e. test: $a: integer expression expected 98. What is the output on your screen of the following sequence of commands: false && echo "linux rocks $?" a. no output b. linux rocks 0 c. linux rocks 1 d. linux rocks 0 e. linux rocks 1 99. Which of these first lines will cause this executable file to be interpreted using the Bash shell? a. !/bin/bash b. !#/bin/bash -u c. /bin/bash -u d. #!/bin/bash e. #/bin/bash 100. What is the output on your screen of the following sequence of commands: a=cow ; b=dog ; touch $a ; test -z $a ; echo $? a. no output b. 1 c. test: $a: integer expression expected d. the number 1 or 0 followed by another 1 or 0 on a new line e. 0 101. Which command sequence correctly searches for the chars and then prints OK if it is found inside the password file? a. if [ test chars /etc/passwd ] ; then echo OK ; fi b. if grep chars