Practice Test #2 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 - 54 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: 5 31 26 39 54 35 2 47 15 25 10 13 11 28 29 23 38 3 21 1 22 36 4 14 34 42 33 43 27 51 17 52 44 53 50 9 40 48 46 19 41 7 18 37 30 6 20 8 16 49 24 12 32 45) 1. Which bash command line below allows programs in the current directory to execute without preceding the names with ./? a. PATH=/usr/bin:.:$HOME b. $PATH=$HOME:/usr/bin:. c. $PATH=/usr/bin:./$HOME d. PATH=./$HOME:/usr/bin e. PATH=/usr/bin/.:$HOME 2. What is the output of this sequence of three shell commands: umask 762 ; touch newfile ; ls -l newfile a. ------xr-x 1 me me 0 Oct 1 1:12 newfile b. -------r-- 1 me me 0 Oct 1 1:12 newfile c. -rwxrw--w- 1 me me 0 Oct 1 1:12 newfile d. --------wx 1 me me 0 Oct 1 1:12 newfile e. -rw-rw--w- 1 me me 0 Oct 1 1:12 newfile 3. How many arguments and options are there to the command: sort -r /dev/null nosuchfile a. ls: 2>/dev/null nosuchfile: No such file or directory b. ls: /dev/null: No such file or directory c. nosuchfile d. ls: nosuchfile: No such file or directory e. no output 5. What minimal permissions must you have on a directory to be able to execute successfully the command ls . from inside the directory? a. r-- b. -wx c. --x d. r-x e. rw- 6. How many arguments are passed to the command by the shell on this command line: cow cow a. 3 b. 4 c. 6 d. 5 e. 7 7. What is the correct syntax to redirect both standard output and standard error into the same output file? a. wc >out 2>&1 foo b. wc >out 2>out foo c. wc 2>&1 >out foo d. wc 2>1 >out foo e. wc >out 2>1 foo 8. Which of the following PATH statements makes the most sense? a. PATH=/bin:/bin/cat:/usr/bin b. PATH=/bin/sh:/usr/bin:/etc:/bin c. PATH=/bin:/usr/bin:/etc/passwd d. PATH=/bin/ls:/etc:/usr/bin e. PATH=/usr:/bin:/usr/bin:/etc 9. Given my directory dir and my file dir/foo owned by me, which permissions allow me to access and change the content (data) in the file dir/foo but not delete the file? a. Permissions 100 on directory dir and 100 on file dir/foo. b. Permissions 300 on directory dir and 200 on file dir/foo. c. Permissions 600 on directory dir and 700 on file dir/foo. d. Permissions 400 on directory dir and 400 on file dir/foo. e. Permissions 500 on directory dir and 600 on file dir/foo. 10. What is the bash shell output of this two command sequence: PATH=/bin/ls:/bin/head:/bin/sh ; head nosuchfile a. head: nosuchfile: No such file or directory b. ls: /bin/head: command not found c. bash: /bin/ls: command not found d. bash: /bin/sh: No such file or directory e. bash: head: command not found 11. Which of the following shell command lines displays only the names in the current directory that are exactly three alphabetic letters long? a. echo [a-zA-Z][a-zA-Z][a-zA-Z] b. echo ??? c. echo [?][?][?] d. echo [0-3][0-3][0-3] e. echo *** 12. 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 100 on directory dir and 200 on file dir/foo. b. Permissions 500 on directory dir and 400 on file dir/foo. c. Permissions 300 on directory dir and 500 on file dir/foo. d. Permissions 300 on directory dir and 300 on file dir/foo. e. Permissions 100 on directory dir and 100 on file dir/foo. 13. Which of these statements is true? a. Only single quotes are strong enough to stop shell glob (wildcard) patterns from expanding. 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. If /y is an empty directory, echo /y/* produces an error message. e. If /x is an empty directory, sort /x/* produces an error message. 14. What is the output of this sequence of three shell commands: umask 547 ; mkdir newdir ; ls -ld newdir a. dr-xr--rwx 1 me me 0 Feb 20 07:55 newdir b. dr--r--rw- 1 me me 0 Feb 20 07:55 newdir c. d-w--w---- 1 me me 0 Feb 20 07:55 newdir d. d-w--wx--- 1 me me 0 Feb 20 07:55 newdir e. d-w--wxrwx 1 me me 0 Feb 20 07:55 newdir 15. What is the output 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. dr-xr-xrwx 2 me me 512 Oct 1 1:12 newdir d. dr--r-xrwx 2 me me 512 Oct 1 1:12 newdir e. d-w--w---- 2 me me 512 Oct 1 1:12 newdir 16. If /bin/foo is a program that outputs mom and /usr/bin/foo is a program that outputs dad what is the output of this shell command sequence: PATH=/bin/foo:/usr/bin/foo:/usr ; foo a. dad b. bash: foo: command not found c. mom d. mom followed by dad e. dad followed by mom 17. In an empty directory, what appears on your screen after this bash command line? ls out 2>/dev/null a. out b. ls: out 2>/dev/null: No such file or directory c. no output d. ls: out: No such file or directory e. ls: /dev/null: No such file or directory 18. What is the correct syntax to redirect both standard output and standard error into the same output file? a. ls -l >foo 2>foo b. ls -l >foo 2>$1 c. ls -l 2>&1 >foo d. ls -l >foo 2>&1 e. ls -l 2>$1 >foo 19. If /bin/bat is a program that outputs foo and /usr/bin/bat is a program that outputs hi what is the output of this shell command sequence: PATH=/usr:/usr/bin:/bin ; bat a. hi followed by foo b. bash: bat: command not found c. foo d. hi e. foo followed by hi 20. What is the correct syntax to redirect both standard output and standard error into the same output file? a. command >out 2>&1 b. command 2>&1 >out c. command 2>out >out d. command 2>1 >out e. command >out 2>1 21. If /bin/foo is a program that outputs dad and /usr/bin/foo is a program that outputs mom what is the output of this shell command sequence: PATH=/usr:/etc:/bin:/usr/bin ; foo a. mom b. dad c. dad followed by mom d. mom followed by dad e. bash: foo: command not found 22. If foo were a file of text containing 50 different lines, what would be the output of this exact command line: diff foo foo a. an error message because diff only allows one file name b. several lines, which are the lines that are different between the two files c. no output d. the contents of file foo would be displayed e. an error message because diff doesn't allow the same file name twice 23. Which bash command line below allows programs in the current directory to execute without preceding the names with ./? a. PATH = ./$HOME:/bin b. PATH=/bin:$HOME:. c. PATH = /bin:$HOME:. d. $PATH=/bin:./$HOME e. $PATH=.:$HOME:/bin 24. Given my directory dir and my file dir/bar owned by me, which permissions allow me to delete the file dir/bar from the directory, but not change the content (data) in the file? a. Permissions 100 on directory dir and 500 on file dir/bar. b. Permissions 100 on directory dir and 300 on file dir/bar. c. Permissions 500 on directory dir and 500 on file dir/bar. d. Permissions 300 on directory dir and 200 on file dir/bar. e. Permissions 300 on directory dir and 400 on file dir/bar. 25. How many arguments are passed to the command by the shell on this command line: pig pig pig a. 9 b. 8 c. 5 d. 7 e. 6 26. If bar is an executable script containing the line: TERM=vt100 ; export TERM what is the output of the following sequence of commands: TERM=linux ; ./bar ; echo "$TERM" a. TERM b. vt100 c. ./bar d. $TERM e. linux 27. How many arguments are passed to the command by the shell on this command line: bat bat bat a. 3 b. 5 c. 7 d. 4 e. 6 28. If cat is an executable script containing the line: TERM=linux ; export TERM what is the output of the following sequence of commands: TERM=vt100 ; ./cat ; echo "$TERM" a. vt100 b. $TERM c. TERM d. linux e. cat 29. How many arguments and options are there to the command: wc mail idallen@ncf.ca d. date >foo ; cp foo/. bar e. mkdir foo ; sleep foo 31. If the file pig contained the word foo, what would be the bash shell output of this two command sequence: PATH=/etc/passwd:/bin/ls:/bin/cat ; /bin/ls pig a. foo b. no output c. /bin/ls: pig: No such file or directory d. pig e. bash: /bin/ls: command not found 32. Which line below is most likely to be the beginning of an error message? a. echo 2>&1 "... " b. echo 1<&2 "... " c. echo 1>&2 "... " d. echo 2>$1 "... " e. echo 2<$1 "... " 33. If dog is an executable script containing the line: umask 0777 what is the output of the following sequence of commands: umask 0022 ; ./dog ; umask a. 0755 b. 0799 c. 0777 d. 0022 e. nothing; no output 34. Which command stops people from using write to put lines of text on your screen? a. chmod 000 b. write n c. stop 0 d. umask 000 e. mesg n 35. 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 36. 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 [0-90-90-9] b. echo [0-9][0-9][0-9] c. echo [1-3][1-3][1-3] d. echo ??? e. echo [1-31-31-3] 37. In an empty directory, what appears on your screen after this bash command line? ls 1>/dev/null nosuchfile a. nosuchfile b. ls: 1>/dev/null nosuchfile: No such file or directory c. no output d. ls: nosuchfile: No such file or directory e. ls: /dev/null: No such file or directory 38. Which of these commands makes a file owned by me, also executable by me? a. chmod x=u ./myfile b. umask 111 myfile c. umask 777 myfile d. chmod x+u myfile e. chmod u+x ./myfile 39. If your PATH variable contains /bin:/usr/bin, what is the output of this bash shell command line? echo '$PATH' a. '/bin:/usr/bin' b. /bin:/usr/bin c. $PATH d. '$PATH' e. echo: $PATH: No such file or directory 40. If the file foo contained the word mom, what would be the bash shell output of this two command sequence: PATH=/bin/ps:/bin/echo:/bin/ls ; /bin/ls foo a. bash: /bin/ls: command not found b. no output c. /bin/ls: foo: No such file or directory d. foo e. mom 41. If foo is an executable script containing the line: PATH=/bin ; export PATH what is the output of the following sequence of commands: PATH=/etc ; ./foo ; echo "$PATH" a. foo b. /etc c. /bin d. $PATH e. /etc:/bin 42. 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-mn-zA-YZ][ab-zAB-YZ][za-yZA-Y] b. echo ??? c. echo [a,zA,Z][a,zA,Z][a,zA,Z] d. echo [azAZ][azAZ][azAZ] e. echo [0-89][01-9][0-45-9] 43. If the file bat contained the word foo, what would be the bash shell output of this two command sequence: PATH=/bin/ls:/bin/who:/etc/passwd ; /bin/ls bat a. bash: /bin/ls: command not found b. no output c. /bin/ls: bat: No such file or directory d. foo e. bat 44. If happy were a file of text containing 50 different lines, what would be the output of this exact command line: cp happy sad ; diff happy sad a. an error message because diff only allows one file name b. several lines, which are the lines that are different between the two files c. no output d. an error message because diff doesn't allow different file names e. the contents of file happy would be displayed 45. What is the output of this sequence of three shell commands: umask 674 ; touch newfile ; ls -l newfile a. -rw-rwxr-- 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. ---x----wx 1 me me 0 Feb 20 07:55 newfile e. --w--wxr-x 1 me me 0 Feb 20 07:55 newfile 46. Which bash 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:.:/usr/bin e. PATH=./$HOME:./bin 47. If /bin/pig is a program that outputs hi and /usr/bin/pig is a program that outputs foo what is the output of this shell command sequence: PATH=/etc:/usr/bin:/bin ; pig a. hi b. bash: pig: command not found c. foo d. hi followed by foo e. foo followed by hi 48. 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 [azAZ][azAZ][azAZ] b. echo [a,zA,Z][a,zA,Z][a,zA,Z] c. echo ??? d. echo [a-zA-Z][a-zA-Z][a-zA-Z] e. echo [a-zA-Za-zA-Za-zA-Z] 49. 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 500 on directory dir and 500 on file dir/bar. b. Permissions 100 on directory dir and 200 on file dir/bar. c. Permissions 300 on directory dir and 500 on file dir/bar. d. Permissions 700 on directory dir and 300 on file dir/bar. e. Permissions 600 on directory dir and 200 on file dir/bar. 50. Which of these first lines will cause this executable file to be interpreted using the Bash shell? a. #!/bin/bash b. #/bin/bash c. !#/bin/bash -u d. /bin/bash -u e. !/bin/bash 51. What is the bash shell output of this two command sequence: PATH=/bin/ls:/bin/cat:/bin/sh ; cat nosuchfile a. bash: /bin/sh: No such file or directory b. bash: cat: command not found c. bash: /bin/ls: command not found d. cat: nosuchfile: No such file or directory e. ls: /bin/cat: command not found 52. Which of these statements is true? a. If /q is an empty directory, echo /q/.* produces an error message. b. The ls dir command looks up the directory argument dir in your $PATH. c. Typing ./script and bash script always give identical results. 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. 53. How many arguments are passed to the command by the shell on this command line: bar bar bar a. 6 b. 7 c. 4 d. 3 e. 5 54. In an empty directory, how many lines are in file out after this bash shell command line: ls . .. nosuchfile 2>out a. 2 b. 1 c. 3 d. no output (empty file) e. 4 Answer Key - DAT2330 - Ian Allen - Fall 2004 - DAT2330 Practice Test - 0% Office use only: 5 31 26 39 54 35 2 47 15 25 10 13 11 28 29 23 38 3 21 1 22 36 4 14 34 42 33 43 27 51 17 52 44 53 50 9 40 48 46 19 41 7 18 37 30 6 20 8 16 49 24 12 32 45 1. a 53. e 2. b 54. b 3. e 4. e Count of a: 9 17% 5. d Count of b: 11 20% 6. a Count of c: 10 19% 7. a Count of d: 11 20% 8. e Count of e: 13 24% 9. e 10. e With 5 choices: 54 11. a 1 2 3 4 5 6 7 8 9 10 11 12 13 12. c 14 15 16 17 18 19 20 21 22 23 13. e 24 25 26 27 28 29 30 31 32 33 14. d 34 35 36 37 38 39 40 41 42 43 15. b 44 45 46 47 48 49 50 51 52 53 16. b 54 17. c 18. d Macro .cmd splits: 21 19. d Macro .ans splits: 0 20. a 21. b 22. c 23. b 24. e 25. e 26. e 27. d 28. a 29. c 30. a 31. d 32. c 33. d 34. e 35. c 36. b 37. d 38. e 39. c 40. d 41. b 42. a 43. e 44. c 45. c 46. b 47. c 48. d 49. b 50. a 51. b 52. d