=============================== Midterm 1 - Unix - with answers =============================== DAT2330 - Ian Allen - Winter 20-1- 45 minutes Evaluation: 42 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. In the output of the command ls -a, a dot that begins a name signifies what? a. A name that is hidden. b. The parent directory. c. The current directory. d. A current file. e. A name with an unprintable character. 2. In the output of the command ls -ai, the one-character name . signifies what? a. The current directory. b. A name that is hidden. c. The parent directory. d. A current file. e. A name with an unprintable character. 3. If you type the command sort verybigfile >out which of the following key sequences will interrupt it and take you immediately back to the command prompt? a. [CTRL-C] b. [CTRL-D] c. [CTRL-I] d. [CTRL-U] e. [CTRL-R] 4. If you type the command sort which of the following key sequences will send an EOF and take you immediately back to the command prompt? a. [CTRL-D] b. [CTRL-C] c. [CTRL-I] d. [CTRL-U] e. [CTRL-R] 5. Which command below removes only this four-character file name containing a special character (and no others): *dog a. rm ./\*dog b. rm .\/*dog c. rm /*dog d. rm \\*dog e. rm ?dog 42 Questions DAT2330 Test #1 - Unix - 10% 45 minutes DAT2330 - Ian Allen - Winter 20-2- 45 minutes 6. Which command below removes only this four-character file name containing a special character (and no others): cat? a. rm "cat?" b. rm cat/? c. rm \cat? d. rm ''cat?'' e. rm ""cat?"" 7. How many arguments does the shell pass to this echo command: echo "cow "y " bat 'man x' " pig'a "hop' a b a. Five arguments. b. Four arguments. c. Six arguments. d. Seven arguments. e. Eleven arguments. 8. How many arguments does the shell pass to this argv command: argv 'And it's not hard, it's just logical.' a. Four arguments. b. Three arguments. c. Five arguments. d. Six arguments. e. Seven arguments. 9. If I am in my home directory named /home/me and x is an empty sub-directory, what is true after this command line: touch ./x/fil ; mv x/./fil x/../../me/./y a. the directory x is still empty b. the directory x now contains only a file named y c. there is a second copy of the file fil in the file named y d. the command fails because the path x/./fil does not exist e. the command fails because the path x/../../me does not exist 10. If I am in my home directory named /home/myhome and sub is an empty sub-directory, what is true after this command line: touch ./fil ; mv sub/../fil ../myhome/cat a. the directory sub/.. now has a file named cat in it b. the directory sub now contains only a file named cat c. there is a second copy of the file fil in the file named cat d. the command fails because the path sub/../fil does not exist e. the command fails because the path ../myhome/cat does not exist 11. If I have a directory owned by me named 1/2, which of the following actions would increase its link count by exactly one? a. create one subdirectory named 1/2/3 b. create one subdirectory named 1/2 c. create one subdirectory named 1/22 d. create one file named 1/2/3 e. create one file named 1/22 42 Questions DAT2330 Test #1 - Unix - 10% 45 minutes DAT2330 - Ian Allen - Winter 20-3- 45 minutes 12. Which of the following is true, given this long directory listing from ls: 755 drwxr-x--x 512 ian user 256 May 30 12:35 dir a. The number 512 is the count of links (names) this directory has. b. The number 512 is the size of this directory. c. The number 256 is the inode number of this directory. d. The number 256 is the count of links (names) this directory has. e. The number 755 is the octal permissions of this directory. 13. Which of the following is true, given this long directory listing from ls: 755 drwxr-x--x 256 ian user 512 May 30 12:35 dir a. The number 512 is the size of this directory. b. The number 512 is the count of links (names) this directory has. c. The number 256 is the inode number of this directory. d. The number 256 is the octal permissions of this directory. e. The number 755 is the count of links (names) this directory has. 14. What is the output of this sequence of three shell commands: echo hi >hi ; head hi >hi ; wc hi a. 0 0 0 hi b. 1 1 3 hi c. 1 1 2 hi d. 2 2 4 hi e. no output 15. What is the output of this sequence of three shell commands: echo hi >wc ; ls wc >wc ; wc wc a. 1 1 3 wc b. 0 0 0 wc c. 1 1 2 wc d. 2 2 4 wc e. no output 16. Which of the following will not cause file1 to become an empty file? a. wc file1 > file1 b. cat file1 > file1 c. sort file1 > file1 d. head file1 > file1 e. tail file1 > file1 17. What would you type to change the permissions on a file to -wxr-x--x? a. chmod 351 file b. chmod 654 file c. chmod 321 file d. chmod 214 file e. chmod 311 file 42 Questions DAT2330 Test #1 - Unix - 10% 45 minutes DAT2330 - Ian Allen - Winter 20-4- 45 minutes 18. What would you type to change the permissions on a file to r-----rw-? a. chmod 406 file b. chmod 102 file c. chmod 322 file d. chmod 122 file e. chmod 654 file 19. Which of these command sequences will make file3 contain all of the content of file1 followed by all of the content of file2? a. cat file1 file2 >file3 b. cp file1 file2 >file3 c. mv file1 file2 >file3 d. ln file1 file2 >file3 e. echo file1 file2 >file3 20. Given this sequence of commands: echo foo >a ; ln a b ; echo bar >>b ; ln a c ; rm a What is contained in file c? a. foo followed by bar b. foo c. bar d. nothing - empty file - no data e. no such file (nonexistent) 21. Which command stops people from using write to put lines of text on your screen? a. mesg n b. write n c. talk n d. chmod n e. w n 22. Which command lists all possible utilities available for editing files? a. apropos edit b. man edit c. finger edit d. which edit e. whereis edit 23. What is in the file x after this command sequence: echo foo >a ; rm b ; echo bar >>b ; cp a b >x a. nothing - empty file - no data b. foo followed by bar c. foo d. bar e. no such file (nonexistent) 42 Questions DAT2330 Test #1 - Unix - 10% 45 minutes DAT2330 - Ian Allen - Winter 20-5- 45 minutes 24. Given this successful sequence of commands: cd /home/foo ; mkdir bar ; cd bar ; chmod -x . Which one of the following subsequent commands will execute without any "permission denied" errors? a. ls /home/foo/bar b. ls /home/foo/bar/. c. ls /home/foo/bar/.. d. ls . e. ls .. 25. What is the output of this successful command sequence? cd /home/foo ; touch dir ; mkdir bar ; pwd a. /home/foo b. /home/bar c. /home/foo/bar d. /home/dir e. /home/foo/dir 26. If my current directory is /home, which of these pathnames is equivalent to the pathname /home/a/b/c? a. ./a/b/c b. /a/b/c c. ./home/a/b/c d. ../a/b/c e. ../home/b/c 27. If /bin/bash is a file name, which of the following pathnames always leads to the same file? a. /../../bin/bash b. /bin/bash/. c. /bin/bash/.. d. ./bin/bash e. /bin/../bash 28. If the current directory contains 5 visible files and 10 visible sub-directories, what is the output of this command: echo */. a. 10 directory names b. 5 file names c. 15 pathnames d. */. e. no output 29. Which of these statements is true? a. you may be able to rename a file even if you do not own the file b. you can change the permissions of any file to which you can write c. you can only remove a file name if the file is writable by you d. you can only remove a file name if the file is owned by you e. you can only make links to files owned by you 42 Questions DAT2330 Test #1 - Unix - 10% 45 minutes DAT2330 - Ian Allen - Winter 20-6- 45 minutes 30. Which command sequence creates a directory into which anyone can put a file, but in which nobody can see the names of the files that are there? a. mkdir protected ; chmod 733 protected b. mkdir protected ; chmod 777 protected c. mkdir protected ; cd protected ; chmod go-x . d. mkdir protected ; cd protected ; chmod go+wx . e. mkdir protected ; chmod 777 . 31. What is the link count of directory foo after this set of successful commands? mkdir foo ; cd foo ; touch a b c a. 2 b. 1 c. 3 d. 4 e. 5 32. 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 y z a. 2 b. 0 c. 1 d. 3 e. 4 33. Which command sequence below does not generate an error message from the last command in the sequence? a. mkdir foo foo/bar ; rmdir foo/bar b. mkdir foo ; ln foo bar c. date >foo ; cp foo/. bar d. cat /etc/passwd > mail idallen@ncf.ca e. mkdir foo foo/bar ; rmdir foo 34. Which Unix command sequence deletes a directory and everything inside it? a. rm -r dir b. rm -all dir c. rmdir -r dir d. rmdir -all dir e. deltree -all dir 35. Which command sequence outputs inode/filename pairs for names in the working directory, sorted by inode number? a. ls -ia | sort -n b. ls -node | sort -n c. echo -i * > sort d. echo * | sort -n e. ls | sort -i 42 Questions DAT2330 Test #1 - Unix - 10% 45 minutes DAT2330 - Ian Allen - Winter 20-7- 45 minutes 36. What does the term "kernel" (or "nucleus") mean? a. that portion of the operating system that is always memory-resident b. software to support many users of the same machine c. software to support more than one program loaded d. applications that are able to share the printer e. a method to get the system loaded into memory from disk/CD/tape/cards 37. Which command sequence below outputs only lines 10-15 of the Unix password file? a. head -15 /etc/passwd | tail -6 b. tail -15 /etc/passwd | head -10 c. head -15 /etc/passwd | tail -5 /etc/passwd d. head -10 /etc/passwd | tail -15 /etc/passwd e. tail -10 /etc/passwd | head -15 /etc/passwd 38. What command shows all the lines in file /etc/group that contain the string idallen? a. grep idallen /etc/group b. grep /etc/group idallen c. cat /etc/group > grep idallen d. cat /etc/group | wc idallen e. grep idallen >/etc/group 39. What command shows your running processes? a. ps b. lsp c. pls d. ls -p e. w -p 40. If file foo contains nine lines, each of which is the number of the line in the file, what is the output of this command: cat foo foo | sort | tail -4 | head -1 a. 8 b. 6 c. 4 d. 1 e. no output 41. If file foo contains nine lines, each of which is the number of the line in the file, what is the output of this command: cat foo foo | sort | uniq | tail -4 | head -1 a. 6 b. 8 c. 4 d. 1 e. no output 42. What is the output of this command sequence: echo foo >file ; echo bar | sort file a. foo b. bar c. foo followed by bar d. bar followed by foo e. an error message 42 Questions DAT2330 Test #1 - Unix - 10% 45 minutes DAT2330 - Ian Allen - Winter 20-8- 45 minutes Answer Key - DAT2330 - Ian Allen - Winter 2003 - DAT2330 Test #1 - Unix - 10% Office use only: 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 1. a Macro .ans splits: 0 2. a 3. a 4. a 5. a 6. a 7. a 8. a 9. a 10. a 11. a 12. a 13. a 14. a 15. a 16. a 17. a 18. a 19. a 20. a 21. a 22. a 23. a 24. a 25. a 26. a 27. a 28. a 29. a 30. a 31. a 32. a 33. a 34. a 35. a 36. a 37. a 38. a 39. a 40. a 41. a 42. a Count of a: 42 100% With 5 choices: 42 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 Macro .cmd splits: 15 42 Questions DAT2330 Test #1 - Unix - 10% 45 minutes