=============================== Midterm 2 - Unix - with answers =============================== DAT2330 - Ian Allen - Winter 2003 45 minutes Evaluation: 40 Questions Name: _________________________ Important Instructions 1. Read all instructions and both sides of all pages. 2. Manage your time when answering questions on this test. Answer the questions you know, first. 1. 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 | sort -r | head -5 | tail -1 a. 8 b. 6 c. 9 d. 7 e. 5 2. How many arguments and options are there to the command: ls -lid /p a. Two arguments: A file name starting with a dash and a /p switch option argument. b. Two arguments, one of which is a single option name and the other is a pathname. c. Two arguments, neither of which is an option. d. Two command line arguments, one of which contains three options. e. Three arguments, one of which contains options and one is a pathname. 3. Which of the following shell command lines displays only the names in the current directory that are exactly three numeric digits long? a. echo [1-3][1-3][1-3] b. echo '[0-9]''[0-9]''[0-9]' c. echo [0-9][0-9][0-9] d. echo '0-9'0-9'0-9' e. echo ??? 4. What is the link count of directory dir after this set of successful commands? mkdir dir ; cd dir ; touch one ; mkdir two a. 4 b. 5 c. 2 d. 1 e. 3 40 Questions DAT2330 Test #2 - Unix - 10% 45 minutes DAT2330 - Ian Allen - Winter 20-2- 45 minutes 5. Which of these statements is true? a. Only single quotes are strong enough to stop shell glob (wildcard) patterns from expanding. b. Typing ./script and bash script always give identical results. c. If /x is an empty directory, sort /x/* produces an error message. d. The cat food command looks up the file name argument food in your $PATH. e. If /y is an empty directory, echo /y/* produces an error message. 6. 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. 40 b. 60 c. 100 d. 160 e. 200 7. If directory /dir contains these three four-character file names: .123, .124, .???, then what is the output of the following bash shell command line: echo /dir/???? a. echo: /dir/????: No such file or directory b. /dir/.123 /dir/.124 /dir/.??? c. no output d. /dir/.123 /dir/.124 e. /dir/???? 8. Which command line displays the contents of the Unix passwd file one page at a time? a. /etc/passwd >less b. less | /etc/passwd c. cat /etc/passwd >less d. less /a/b b. grep -v /a/b /a/b >/a/b c. sort -r /a/b >/a/b d. ls /a/b >/a/b e. tail -5 /a/b >/a/b 10. What is the output of this sequence of three shell commands: umask 547 ; mkdir newdir ; ls -ld newdir a. dr--r--rw- 1 me me 0 Feb 20 07:55 newdir b. d-w--wx--- 1 me me 0 Feb 20 07:55 newdir c. d-w--w---- 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 40 Questions DAT2330 Test #2 - Unix - 10% 45 minutes DAT2330 - Ian Allen - Winter 20-3- 45 minutes 11. Which of the following bash PATH statements makes the most sense? a. PATH=/bin:/bin/cat:/usr/bin b. PATH=/bin/ls:/etc:/usr/bin c. PATH=/bin/sh:/usr/bin:/etc:/bin d. PATH=/bin:/usr/bin:/etc/passwd e. PATH=/bin:/usr/bin:/etc 12. 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 a. 1 b. 4 c. 3 d. 2 e. 5 13. 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 200 on directory dir and 200 on file dir/foo. c. Permissions 400 on directory dir and 400 on file dir/foo. d. Permissions 600 on directory dir and 700 on file dir/foo. e. Permissions 100 on directory dir and 100 on file dir/foo. 14. 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. ddp c. :dp d. ddP e. DDp 15. What is in the file named file after this command sequence: echo a >x ; echo b >>x ; mv x y >file a. nothing - file is empty - no data b. no such file (nonexistent file) c. a d. b e. a followed by b 16. What is the output of this command sequence: echo dog >one ; echo cow | head -2 one a. an error message b. dog c. cow d. cow followed by dog e. dog followed by cow 40 Questions DAT2330 Test #2 - Unix - 10% 45 minutes DAT2330 - Ian Allen - Winter 20-4- 45 minutes 17. 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/?? b. rm dir/*1 c. rm dir/\?? d. rm dir/1* e. rm dir/?1 18. Given this long listing: drwxr-xr-x 2048 root root 4096 Jan 20 14:22 /dir How many subdirectories lie immediately under /dir? a. 4094 b. 4096 c. there is not enough information shown to answer the question d. 2048 e. 2046 19. What Unix command line will show you all of the processes currently running, for all userids? a. which ps b. finger ps c. ps all d. whereis ps e. ps aux 20. Which command sequence below does not generate an error message from the last command in the sequence? a. date >foo ; cp foo/. bar b. mkdir foo foo/bar ; rmdir foo c. cat /etc/passwd > mail idallen@ncf.ca d. mkdir one one/two ; rmdir one/two e. mkdir foo ; ln foo bar 21. 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 -4 | head -1 a. 5 b. 7 c. 9 d. 6 e. 8 22. 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 100 on directory dir and 200 on file dir/foo. c. Permissions 300 on directory dir and 500 on file dir/foo. d. Permissions 100 on directory dir and 100 on file dir/foo. e. Permissions 300 on directory dir and 300 on file dir/foo. 40 Questions DAT2330 Test #2 - Unix - 10% 45 minutes DAT2330 - Ian Allen - Winter 20-5- 45 minutes 23. What is the output of this sequence of three shell commands: echo x >abc ; ls >abc abc ; wc abc a. 1 1 2 abc b. 1 1 3 abc c. 1 1 4 abc d. 0 0 0 abc e. no output 24. Which command line below does not show any lines from inside the file dog? a. more dog b. head dog c. tail dog d. less dog e. ls dog 25. What is the output of this sequence of three shell commands: umask 674 ; touch newfile ; ls -l newfile a. ---x----wx 1 me me 0 Feb 20 07:55 newfile b. -rw-rwxr-- 1 me me 0 Feb 20 07:55 newfile c. --w--wxr-x 1 me me 0 Feb 20 07:55 newfile d. -rw-rw-r-- 1 me me 0 Feb 20 07:55 newfile e. --------w- 1 me me 0 Feb 20 07:55 newfile 26. 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 ../home/me/foo c. cp ../home/me/../etc/passwd ./me/./foo d. cp ../etc/passwd ../me/foo e. cp me/../../etc/passwd me/foo 27. If the file foo contained the word mom, what would be the bash shell output of this two command sequence: PATH=/etc/passwd:/bin/ls:/bin/cat ; /bin/ls foo a. /bin/ls: foo: No such file or directory b. mom c. bash: /bin/ls: command not found d. no output e. foo 28. 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. the contents of file foo would be displayed b. an error message because diff only allows one file name c. several lines, which are the lines that are different between the two files d. an error message because diff doesn't allow the same file name twice e. no output 40 Questions DAT2330 Test #2 - Unix - 10% 45 minutes DAT2330 - Ian Allen - Winter 20-6- 45 minutes 29. If /bin/foo is a program that outputs hi and /usr/bin/foo is a program that outputs mom what is the output of this shell command sequence: PATH=/etc:/usr/bin:/bin ; foo a. bash: foo: command not found b. mom c. hi d. hi followed by mom e. mom followed by hi 30. Which of these statements is true? a. Either single or double quotes will stop shell glob (wildcard) patterns from expanding. 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. The ls dir command looks up the directory argument dir in your $PATH. 31. 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. 120 b. 70 c. no lines (empty file) d. 50 e. 80 32. Which Unix command sequence deletes a directory and everything inside it? a. rm -all dir b. rm -r dir c. rmdir -all dir d. rmdir -r dir e. deltree -all dir 33. How many arguments and options are there to the command: wc -l foo file bar haven a. The command file sees three arguments. b. Error: The command name is missing from the command line. c. The command file sees two arguments. d. The command foo sees only two arguments e. The command foo sees three arguments. 39. How can you ask the bash (Linux) 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 ALT key. b. Type [ALT]-[F2] the shell will present a menu of commands. c. Type [CONTROL]-[ALT]-[DEL] and the shell will present a menu of commands. d. You can type the first part of the command or file name and press the TAB key. e. Type [CONTROL]-[D] and the shell will present a menu of commands. 40. What minimal permissions must you have on a directory to be able to execute successfully the command ls . from inside the directory? a. rw- b. --x c. r-- d. -wx e. r-x 40 Questions DAT2330 Test #2 - Unix - 10% 45 minutes DAT2330 - Ian Allen - Winter 20-8- 45 minutes Answer Key - DAT2330 - Ian Allen - Winter 2003 - DAT2330 Test #2 - Unix - 10% Office use only: 22 4 16 30 7 10 18 40 36 2 12 33 19 34 25 26 17 35 38 32 21 20 24 39 1 28 13 23 14 8 9 29 5 31 3 11 27 6 37 15 1. d Macro .cmd splits: 17 2. d Macro .ans splits: 0 3. c 4. e 5. c 6. b 7. e 8. d 9. d 10. b 11. e 12. c 13. a 14. b 15. a 16. b 17. c 18. e 19. e 20. d 21. d 22. c 23. c 24. e 25. e 26. e 27. e 28. e 29. b 30. a 31. b 32. b 33. e 34. e 35. c 36. e 37. a 38. c 39. d 40. e Count of a: 4 10% Count of b: 7 18% Count of c: 8 20% Count of d: 7 18% Count of e: 14 35% With 5 choices: 40 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 40 Questions DAT2330 Test #2 - Unix - 10% 45 minutes