Practice Test #3 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 - 51 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. What is the output on your screen of the following sequence of commands: x=1 ; touch x ; test ! -z $x ; echo $? a. no output b. the number 1 or 0 followed by another 1 or 0 on a new line c. 0 d. 1 e. test: $x: integer expression expected 2. In a directory containing one file named dog, what appears on your screen after this command line? 2>/dev/null ls nosuchfile a. ls: nosuchfile: No such file or directory b. dog c. bash: 2>/dev/null: command not found d. nosuchfile e. no output on screen 3. 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 [ grep foo bar ] ; then date ; fi c. if grep wc ; cat wc b. apropos bash | wc c. man bash | wc d. which bash | wc e. whereis bash | wc 6. Which command line shows the current date? a. bash >date ; cat date b. date | bash c. echo date | bash d. bash /etc/passwd && echo OK b. grep chars >/etc/passwd || echo OK c. grep chars /etc/passwd || echo OK d. grep chars /dev/null ls * a. * b. no output on screen c. ls: *: No such file or directory d. bash: 1>/dev/null: command not found e. dog 30. 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. uniq -c foo | sort -nr | head -1 c. cat sort foo | uniq -c | sort -nr | head -1 d. sort foo > uniq -c ; sort -nr uniq | head -1 e. sort | uniq -c | sort -nr | head -1 foo 31. In an empty directory, how many lines are in file out after this bash shell command line: ls . .. nosuchfile 2>out a. 2 b. no output (empty file) c. 4 d. 1 e. 3 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 "" -eq $a ; then date ; fi b. if [ "$a" = * ] ; then date ; fi c. if [ '''' = ''$a'' ] ; then date ; fi d. if test "" = "$a" ; then date ; fi e. if [ $a = /dev/null ] ; then date ; fi 33. If a=cow and b=dog then what is the output on your screen of the following sequence of commands: [ $a = dog -o $b = dog ] ; echo $? a. 1 b. the number 1 or 0 followed by another 1 or 0 on a new line c. 0 d. test: $a: integer expression expected e. no output 34. What is the output on your screen of the following sequence of commands: i=0 ; test $i = 00 ; echo $? a. 1 b. no output c. 0 d. the number 0 or 1 followed by another 0 or 1 on a new line e. test: $i: integer expression expected 35. Which command line tells you the recursive count of all pathnames under the current directory and all subdirectories? a. wc "$PATH" b. ls | wc c. wc . d. find | wc e. wc * 36. What is the output on your screen of the following sequence of commands: a=cow ; b=dog ; touch $a ; test -z $a ; echo $? a. 1 b. 0 c. test: $a: integer expression expected d. no output e. the number 1 or 0 followed by another 1 or 0 on a new line 37. 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. 1 c. the number 1 or 0 followed by another 1 or 0 on a new line d. 0 e. test: $a: integer expression expected 38. If a=cow and b=dog then what is the output on your screen of the following sequence of commands: if $a = $b ; then echo $a ; fi a. no output b. cow c. test: cow: integer expression expected d. test: $a: integer expression expected e. bash: cow: command not found 39. Which command line locates scripts in the /bin directory? a. ls /bin/* | file | grep script b. cat /bin/* | file | grep script c. cat /bin | file | grep script d. file /bin/* | grep script e. file /bin | grep script 40. 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. 0 c. no output d. the number 0 or 1 followed by another 0 or 1 on a new line e. 1 41. What is the output on your screen of the following sequence of commands: a=1 ; b=2 ; test $a -ge $b ; echo $? a. no output 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. 0 42. What is the output on your screen of the following sequence of commands: x=0 ; test $x ; echo $? a. no output b. the number 0 or 1 followed by another 0 or 1 on a new line c. 1 d. 0 e. test: $x: integer expression expected 43. 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. 1 b. test: $a: integer expression expected c. the number 1 or 0 followed by another 1 or 0 on a new line d. no output e. 0 44. What is the output on your screen of the following command sequence: a=1 ; b=2 ; test $a -ge $b ; 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 45. Which command sequence below always outputs just the date only if the first argument is either a file or a directory? a. if [ "$1" -eq -f -o "$1" -eq -d ]; then date ; fi b. if [ -f || -d "$1" ]; then date ; fi c. if [ -f -o -d "$1" ]; then date ; fi d. if [ -f "$1" -o -d "$1" ]; then date ; fi e. if [ "-f $1" || "-d $1" ]; then date ; fi 46. In an empty directory, how many lines are in file foo after this command line: ls nosuchfile . .. 2>foo a. 2 b. empty file (no data) c. 1 d. 4 e. 3 47. Which command sends a file to a remote machine foo.ca? a. mv one foo.ca:two b. cat one >foo.ca:two c. scp one >foo.ca:two d. cp one foo.ca:two e. scp one foo.ca:two 48. In an empty directory, how many lines are in file bar after this command line: ls . nosuchfile 1>bar a. 2 b. empty file (no data) c. 1 d. 4 e. 3 49. What is the output on your screen of the following sequence of commands: x=cow ; y=dog ; touch $x ; 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. no output e. test: $x: integer expression expected 50. 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}' 51. Which command sequence correctly compares the numbers and prints OK? a. if [ 2 > 1 ] ; then echo OK ; fi b. if [ ! 2 < 1 ] ; then echo OK ; fi c. if ( 1 let 2 ) ; then echo OK ; fi d. if ( let 2 > 1 ) ; then echo OK ; fi e. if [ 1 -lt 2 ] ; then echo OK ; fi Answer Key - NET2003 - Ian Allen - Winter 2006 - NET2003 Practice Test 1. c With 5 choices: 51 2. e 3. c Macro .cmd split with indent: 20 4. d 5. c 6. c 7. c 8. c 9. e 10. b 11. c 12. e 13. b 14. a 15. d 16. d 17. c 18. a 19. e 20. d 21. e 22. c 23. c 24. c 25. d 26. c 27. a 28. c 29. b 30. a 31. d 32. d 33. c 34. a 35. d 36. a 37. b 38. e 39. d 40. b 41. b 42. d 43. e 44. b 45. d 46. c 47. e 48. c 49. b 50. e 51. e Count of a: 6 12% Count of b: 8 16% Count of c: 16 31% Count of d: 11 22% Count of e: 10 20%