Practice Test #4 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 - 100 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: 58 66 54 15 33 85 59 86 41 83 7 69 26 37 8 3 10 27 38 62 65 60 31 42 21 95 13 71 81 40 2 61 67 43 32 50 75 49 99 53 63 44 18 17 87 45 88 5 29 6 16 23 48 51 22 19 72 68 4 34 28 82 55 14 77 1 74 98 73 46 11 57 97 100 93 36 91 80 76 90 30 89 35 24 52 20 12 96 39 94 84 78 47 79 9 56 25 92 70 64) 1. Which line below puts the count of the number of lines in the password file into the variable foo? a. foo=[ cat -l /etc/passwd ] b. foo=$( wc -l abc ; ls >abc abc ; wc abc a. 1 1 3 abc b. 1 1 2 abc c. 0 0 0 abc d. no output e. 1 1 4 abc 3. Which of these first lines will cause this executable file to be interpreted using the Bash shell? a. !#/bin/bash -u b. /bin/bash -u c. #/bin/bash d. #!/bin/bash e. !/bin/bash 4. What is the output on your screen of the following command sequence: cd /bin && echo "echo $(pwd)" a. echo /bin b. /bin c. echo 0pwd) d. echo $(pwd) e. no output 5. What is the output of this sequence of three shell commands: umask 457 ; mkdir newdir ; ls -ld newdir a. d-wx-w---- 2 me me 512 Oct 1 1:12 newdir b. dr-xr-xrwx 2 me me 512 Oct 1 1:12 newdir c. dr--r-xrwx 2 me me 512 Oct 1 1:12 newdir d. d-wx-w-rwx 2 me me 512 Oct 1 1:12 newdir e. d-w--w---- 2 me me 512 Oct 1 1:12 newdir 6. What is true about this output from ls -il foo bar? 816 -rw-r--r-- 2 root root 3 Jan 24 01:03 foo 817 -rw-r--r-- 2 root root 3 Jan 24 01:03 bar a. foo and bar are two of three names for this file b. foo and bar each have three names (six names total) c. foo and bar are names for different files d. foo and bar are names for the same file e. this output is not possible 7. 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 8. What is true about this output from ls -il foo bar? 861 -rw-r--r-- 2 root root 3 Jan 24 01:03 foo 861 -rwxr-xr-x 2 bin bin 3 Nov 12 12:55 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 three names (six names total) e. foo and bar are names for different files 9. 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. no lines (empty file) b. 50 c. 120 d. 80 e. 70 10. What appears on your screen after this sequence of commands: echo one >x ; cp x y ; echo two >>y ; sort x >y ; cat y a. empty file - no output on the screen b. two followed by one c. two d. one followed by two e. one 11. What is the output on your screen of the following command sequence: echo hi >wc ; wc wc >hi ; cat hi a. 0 0 0 wc b. hi c. no output d. 1 1 2 wc e. 1 1 3 wc 12. 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- 13. If bat=12 and cat=99 then which of the following command lines outputs only the word hi (and nothing else)? a. [!bat = cat] && echo hi b. [ bat -ne cat ] && echo hi c. [bat -eq 12] || echo hi d. [bat!=bat] || echo hi e. [ bat = bat ] && echo hi 14. 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 600 on directory dir and 700 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 100 on directory dir and 100 on file dir/bar. 15. What is the output on your screen of the following command sequence: date='Friday March 12' ; test date = date a. Fri Mar 12 10:20:39 EST 2004 b. test: too many arguments c. no output d. 1 e. 0 16. 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. aaa b. bash: aaa: command not found c. test: $a: integer expression expected d. test: aaa: integer expression expected e. no output 17. What is the output on your screen of the following command sequence: a=sky ; touch $a ; test -z $a ; echo $? a. test: $a: integer expression expected b. no output c. 0 d. sky e. 1 18. How many arguments and options are there to the command: wc -l sixsix ; mv sixsix four ; cp four hi ; gzip hi a. 5 b. 4 c. 2 d. 6 e. 3 27. What is the output on your screen of the following command sequence: x=1 ; y=2 ; test $x -le $y ; echo $? a. 0 b. test: $x: integer expression expected c. no output d. the number 0 or 1 followed by another 0 or 1 on a new line e. 1 28. What is the link count of directory dir after this set of successful commands? mkdir a ; mkdir a/b ; mkdir a/c ; mkdir a/b/c a. 3 b. 5 c. 2 d. 4 e. 1 29. If file foo occupies one disk block, how many disk blocks are in use after this sequence of commands: cp foo bar ; ln bar one ; cp one two ; ln one ten a. 5 blocks b. 1 block c. 4 blocks d. 2 blocks e. 3 blocks 30. 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 [1-3][1-3][1-3] b. echo [1-31-31-3] c. echo [0-9][0-9][0-9] d. echo [0-90-90-9] e. echo ??? 31. If variable x might contain nothing (a null value - defined but empty), which 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" = * ] ; then echo OK ; fi d. if [ $x -eq "" ] ; then echo OK ; fi e. if [ "$x" = "" ] ; then echo OK ; fi 32. If bar is an executable script containing the line dog=bat then what is the output of this sequence of three commands: dog=cat ; ./bar ; echo "the '$dog' ate" a. the $dog ate b. the 'dog' ate c. the 'bat' ate d. the '$dog' ate e. the 'cat' ate 33. 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. Type [CONTROL]-[ALT]-[DEL] and the shell will present a menu of commands. c. Type [CONTROL]-[D] and the shell will present a menu of commands. d. Type [ALT]-[F2] the shell will present a menu of commands. e. You can type the first part of the command or file name and press the ALT key. 34. What is in the file named file after this command sequence: echo a >c ; echo b >>c ; mv c d >file a. b b. nothing - file is empty - no data c. a followed by b d. no such file (nonexistent file) e. a 35. What is the output of this sequence of three shell commands: umask 762 ; touch newfile ; ls -l newfile a. -------r-- 1 me me 0 Oct 1 1:12 newfile b. --------wx 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. ------xr-x 1 me me 0 Oct 1 1:12 newfile 36. 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. cat /etc/passwd > mail idallen@ncf.ca c. mkdir foo foo/bar ; rmdir foo d. date >foo ; cp foo/. bar e. mkdir foo ; ln foo 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. 1 b. 3 c. 5 d. 4 e. 2 38. 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 -10 /etc/passwd | tail -5 /etc/passwd c. head -15 /etc/passwd | tail -6 d. tail -15 /etc/passwd | head -5 e. tail -10 /etc/passwd | head -15 /etc/passwd 39. 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. no output on screen b. $? c. 0 d. 1 e. an error message 40. Which of these commands makes a file owned by me, also executable by me? a. chmod x=u ./myfile b. chmod u+x ./myfile c. chmod x+u myfile d. umask 111 myfile e. umask 777 myfile 41. Which Unix command sequence deletes a directory and everything inside it? a. rmdir -r dir b. rm -r dir c. rmdir -all dir d. deltree -all dir e. rm -all dir 42. What is the output of this command sequence: echo bat >one ; echo sky | head -2 one a. an error message b. sky followed by bat c. bat d. bat followed by sky e. sky 43. In an empty directory, what is the length of the longest file name created by the following two-command sequence: var='a ab abc abcd abcde' ; touch $var a. 15 characters b. 3 characters c. 5 characters d. 4 characters e. 19 characters 44. In an empty directory, what is the length of the longest file name created by the following shell two-command sequence: var='a ab abc abcd abcde' ; touch "$var" a. 15 characters b. 4 characters c. 19 characters d. 5 characters e. 3 characters 45. What is true about this output from ls -ild foo bar? 816 -rwxr-xr-x 2 root root 3 Jan 24 01:03 foo 816 drwxr-xr-x 2 root root 3 Jan 24 01:03 bar a. foo and bar are names for the same file b. foo and bar are two of three names for this file c. foo and bar are names for different files d. foo and bar each have three names (six names total) e. this output is not possible 46. If directory /dir contains these three four-character file names: .123, .124, .???, then what is the output of the following command line: echo /dir/???? a. echo: /dir/????: No such file or directory b. /dir/.123 /dir/.124 /dir/.??? c. /dir/???? d. /dir/.123 /dir/.124 e. no output 47. What is true about this output from ls -il foo bar? 871 -r-------- 2 bin bin 3 Nov 12 12:55 foo 871 -r-------- 2 bin bin 3 Nov 12 12:55 bar a. this output is not possible b. foo and bar are names for the same file c. foo and bar are two of three names for this file d. foo and bar are names for different files e. foo and bar each have three names (six names total) 48. If a=ant and b=bat then what is the output on your screen of the following command sequence: [ $a = ant -a $b = ant ] ; echo $? a. the number 1 or 0 followed by another 1 or 0 on a new line b. test: $a: integer expression expected c. 0 d. 1 e. no output 49. what is the output on your screen of the following command sequence: true && echo Linux Rocks $? a. Linux Rocks 1 b. Linux Rocks ? c. Linux Rocks 0 d. no output e. Linux Rocks $? 50. 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. 1 1 2 wc d. 0 0 0 wc e. wc 51. In an empty directory, what is the length of the longest file name created by the following sequence: var='a ab abc abcd abcde' ; touch '$var' a. 3 characters b. 4 characters c. 5 characters d. 19 characters e. 15 characters 52. A shell script named bar is executed as follows: ./bar 1 2 "3 4" 5 Inside the script is the line: echo "$3" What is the output from this line? a. 3 4 b. 2 3 4 c. $3 d. "3 e. 1 2 3 53. Which of the following statements is true about this shell command line: >bar zoom bar haven a. The command zoom sees three arguments. b. The command zoom sees two arguments. c. The command bar sees only two arguments d. Error: The command name is missing from the command line. e. The command bar sees three arguments. 54. If the file bat contained the word foo, what would be the 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. no output e. bash: /bin/ls: command not found 55. If a bash shell script named sky contains the line: if [ "$1" = '$2' ] ; then echo SAME ; fi then which of the following command lines will produce SAME as output? a. ./sky cow cow b. ./sky $2 $2 c. ./sky "cow" 'cow' d. ./sky "$1" '$2' e. ./sky '$2' cow 56. Which command sequence correctly searches for the chars and then prints OK if it is found inside the password file? a. if grep chars x ; ln x y ; echo two >>y ; sort x >y ; cat y a. two b. empty file - no output on the screen c. one followed by two d. one e. two followed by one 63. Which command line below does not show any lines from inside the file bat? a. more bat b. head bat c. less bat d. tail bat e. ls bat 64. What is the output on your screen of the following command sequence: cd /etc/passwd && echo "in $(pwd)" a. in $(pwd) b. no output c. in /etc d. in 0pwd) e. bash: cd: /etc/passwd: Not a directory 65. What will appear on your screen after this sequence of commands: echo one >x ; ln x y ; echo two >y ; echo ten >x ; cat y a. one b. no output on screen c. one followed by two and ten d. two e. ten 66. 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 [ $a==$b ] ; then echo OK ; fi c. if test a -eq b ; then echo OK ; fi d. if [ a = b ] ; then echo OK ; fi e. if [ $a -eq $b ] ; then echo OK ; fi 67. What is the resulting link count of empty directory dir after this set of successful commands? cd dir ; touch foo ; ln foo one ; ln foo two a. 4 b. 5 c. 1 d. 2 e. 3 68. 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. 0 c. $? d. an error message e. no output on screen 69. What is the link count of directory dir after this set of successful commands? mkdir dir ; touch foo ; cd dir ; ln ../foo bar a. 3 b. 5 c. 4 d. 2 e. 1 70. 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* 71. What is the output on your screen of the following command sequence: i=0 ; test $i = 00 ; echo $? a. no output b. test: $i: integer expression expected c. the number 0 or 1 followed by another 0 or 1 on a new line d. 1 e. 0 72. 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 "... " 73. Which command line copies all the files from directory a to directory b? a. cd a ; tar xvf /tmp/i . ; cd ../b ; tar czf /tmp/i b. cd a ; tar -rc /tmp/i . ; cd ../b ; tar -rx /tmp/i c. cd a ; tar -r /tmp/i . ; cd ../b ; tar -rx /tmp/i d. cd a ; tar czf /tmp/i . ; cd ../b ; tar xvf /tmp/i e. cd a ; tar cf /tmp/i . ; cd ../b ; tar xf /tmp/i 74. 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. $? b. 0 c. an error message d. 1 e. no output on screen 75. The correct option to enable warning messages from the g++ compiler is: a. +Warn b. -wALL c. -Wall d. -warn e. -wall 76. How many arguments are passed to the command by the shell on this command line: bat bat bat a. 3 b. 4 c. 5 d. 6 e. 2 77. A Makefile contains the following lines: bar: rm one two This means: a. if the user types "make one", items one and two will be removed b. the syntax "bar:" is not valid in a Makefile target c. if the user types "make two", items one and two will be removed d. if the user types "make rm", items one and two will be removed e. if the user types "make bar", items one and two will be removed 78. Who is the owner of file bar after you execute this sequence of commands in your home directory: ln /etc/passwd foo ; ln foo one ; ln one two ; ln two bar a. the file is owned by home b. you cannot execute the given commands; no file will be created c. the file is owned by passwd d. the file is owned by root e. you own the file bar 79. 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. 3 b. 2 c. 1 d. 5 e. 4 80. A Makefile contains the following target: foo: bar ant which means: a. items foo and bar depend on item ant b. item foo depends on items bar and ant c. the syntax "foo:" is not valid in a Makefile target d. items bar and ant depend on item foo e. item ant depends on items foo and bar 81. what is the output on your screen of the following command sequence: false && echo "hello there $?" a. hello there 1 b. hello there 0 c. hello there 1 d. hello there 0 e. no output 82. What is true about this output from ls -il foo bar? 871 -r-------- 3 bin bin 2 Apr 22 10:15 foo 872 -r-------- 3 bin bin 2 Apr 22 10:15 bar a. foo and bar each have three names (six names total) b. foo and bar are two of three names for this file c. foo and bar each have two names (four names total) d. this output is not possible e. foo and bar are names for the same file 83. 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. $a d. '.1* .2*' e. .1 .2 84. 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 85. 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. hi b. foo c. hi followed by mom d. bash: bat: command not found e. foo followed by hi 86. 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 | cat | tail -5 | head -1 a. 8 b. 7 c. 6 d. 5 e. 9 87. What is the output on your screen of the following command sequence: a=1 ; b=2 ; test $a -ge $b ; 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 88. In an empty directory, what is the length of the longest file name after this sequence of commands? echo hi >four ; cp four five5 ; mv five5 hi ; bzip2 hi a. 5 b. 6 c. 3 d. 2 e. 4 89. 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-Z][a-zA-Z][a-zA-Z] c. echo [a-zA-Za-zA-Za-zA-Z] d. echo ??? e. echo [azAZ][azAZ][azAZ] 90. The default output file generated by the C and C++ compilers is named: a. a.out b. argv c. a.c++ d. a.cpp e. a.o 91. What appears on your screen after this sequence of commands: echo one >x ; ln x y ; echo two >>y ; sort x a. two b. one c. two followed by one d. empty file - no output on the screen e. one followed by two 92. What will appear on your screen if you execute this sequence of commands in your home directory: ln /etc/passwd foo ; ln foo bar ; echo hi >bar ; cat bar a. bar b. hi c. an error message and then hi d. an error message and then the contents of the password file e. the conents of the password file followed by hi 93. Which of the following bash PATH statements makes the most sense? a. PATH=/bin:/bin/cat:/usr/bin b. PATH=/bin:/usr/bin:/etc c. PATH=/bin/ls:/etc:/usr/bin d. PATH=/bin:/usr/bin:/etc/passwd e. PATH=/bin/sh:/usr/bin:/etc:/bin 94. What will appear on your screen if you execute this sequence of commands: echo 1 >x ; ln x y ; echo 2 >y ; chmod 077 y ; cat x a. no output on screen b. an error message c. 1 d. 2 e. 1 followed by 2 95. What is the output on your screen of the following command sequence: f=1 ; touch f ; test ! -z $f ; echo $? a. 0 b. the number 1 or 0 followed by another 1 or 0 on a new line c. no output d. 1 e. test: $f: integer expression expected 96. Which command line displays the contents of the Unix passwd file one page at a time? a. less less d. /etc/passwd >less e. less | /etc/passwd 97. 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. the file names 1 through 123, surrounded by quotes b. * c. "$glob" d. the file names 1 through 123 e. $glob 98. The correct g++ compiler suffix for a C++ source file is: a. .gpp b. .C++ c. .cplus d. .g++ e. .cpp 99. Select the correct bash shell order of command line processing: a. aliases, variables, redirection, globs b. aliases, globs, variables, redirection c. aliases, variables, globs, redirection d. aliases, redirection, variables, globs e. redirection, aliases, globs, variables 100. Which of the command lines below can generate a non-empty file? a. ls /out >/out b. sort -r /out >/out c. tr abc ABC /out d. grep -v /out /out >/out e. tail -5 /out >/out Answer Key - DAT2330 - Ian Allen - Fall 2004 - DAT2330 Practice Test - 0% Office use only: 58 66 54 15 33 85 59 86 41 83 7 69 26 37 8 3 10 27 38 62 65 60 31 42 21 95 13 71 81 40 2 61 67 43 32 50 75 49 99 53 63 44 18 17 87 45 88 5 29 6 16 23 48 51 22 19 72 68 4 34 28 82 55 14 77 1 74 98 73 46 11 57 97 100 93 36 91 80 76 90 30 89 35 24 52 20 12 96 39 94 84 78 47 79 9 56 25 92 70 64 1. b 53. b 2. e 54. a 3. d 55. e 4. a 56. a 5. a 57. a 6. c 58. a 7. a 59. e 8. a 60. b 9. e 61. a 10. e 62. b 11. e 63. e 12. a 64. e 13. e 65. e 14. a 66. e 15. c 67. d 16. b 68. e 17. e 69. d 18. b 70. b 19. b 71. d 20. b 72. d 21. b 73. e 22. a 74. d 23. e 75. c 24. a 76. b 25. c 77. e 26. a 78. d 27. a 79. e 28. d 80. b 29. e 81. e 30. c 82. a 31. e 83. c 32. e 84. d 33. a 85. b 34. b 86. d 35. a 87. e 36. a 88. b 37. c 89. b 38. c 90. a 39. d 91. e 40. b 92. d 41. b 93. b 42. c 94. b 43. c 95. a 44. c 96. a 45. e 97. b 46. c 98. e 47. b 99. d 48. d 100. a 49. c 50. d 51. b 52. a Count of a: 24 24% Count of b: 23 23% Count of c: 13 13% Count of d: 15 15% Count of e: 25 25% With 5 choices: 100 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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 Macro .cmd splits: 42 Macro .ans splits: 0