CEG 333 Introduction to UNIX Wright State University Midterm Examination #1 Fall Quarter, 2005 Name: Student Number: READ THESE INSTRUCTIONS This is an open-book exam. The use of the notes contained in your class portfolio is permitted. The questions on this examination require you to provide answers similar to those you have seen in lecture, used in the course homework assignments, or presented in the course textbook. Answer all questions in the spaces indicated and only in the spaces indicated. Read each question carefully and work as rapidly as you can without being careless. Academic Honesty At the end of the examination, please sign: In recognition of and in the spirit of the Wright State University policies of academic honesty, I certify that I have neither given nor received unpermitted aid in this examination. Signature: Only questions about these instructions, typing, or copying errors will be answered during the exam. If you are not sure what a question means, state your interpretation and proceed. Use the most direct interpretation and select the best answer for that interpretation. DO NOT BEGIN UNTIL INSTRUCTED TO DO SO
Dr. Doom Page 2 of 6 Consider the following typescript when answering the questions on this page. Do not assume that any other commands are executed between the creation of this typescript and the command answering the question. <w001ted@unixapps1:~ > echo $HOME /common/users2/cse/w001ted <w001ted@unixapps1:~ > pwd /common/users2/cse/w001ted <w001ted@unixapps1:~ > ls l drwx------ 4 w001ted users 512 Sep 15 2004 bin drwx------ 4 w001ted users 512 Sep 25 21:34 reddwarf drwx------ 2 w001ted users 512 Sep 25 21:34 tmp <w001ted@unixapps1:~ > ls l reddwarf/ drwx------ 2 w001ted users 512 Sep 25 21:34 starbug1 drwx------ 2 w001ted users 512 Sep 25 21:33 starbug2 <w001ted@unixapps1:~ > ls l reddwarf/starbug1 -rw------- 1 w001ted users 0 Sep 25 21:10 lister -rw------- 1 w001ted users 0 Sep 25 21:10 thecat <w001ted@unixapps1:~ > ls l reddwarf/starbug2 -rw------- 1 w001ted users 0 Sep 25 21:33 holly -rw------- 1 w001ted users 0 Sep 25 21:30 kryten -rw------- 1 w001ted users 0 Sep 25 21:30 rimmer 1. Which of the following will move kryten from starbug2 into starbug1? a. mv ~/reddwarf/starbug2/kryten reddwarf/starbug1 b. mv reddwarf/starbug2/kryten ~/reddwarf/starbug1/kryten c. mv starbug2/kryten starbug1/kryten e. a. b. and c. 2. Which of the following commands would change your current directory to starbug2? a. cd starbug2 b. cd ~/reddwarf/starbug2 c. cd /common/users2/cse/w001ted/reddwarf/starbug2 3. Which of the following are absolute paths to the file holly? a. /reddwarf/starbug2/holly b. ~/reddwarf/starbug2/holly c. /common/users2/cse/w001ted/reddwarf/starbug2/holly 4. Which of the following commands will create a directory named ace in reddwarf? a. makedir reddwarf/ace b. newdir ace c. nwdir reddwarf/ace d. nwdir ace e. mkdir reddwarf/ace 5. Which of the following commands would remove the file named rimmer? a. rm rimmer b. rm starbug2/rimmer c. rm reddwarf/starbug2/rimmer d. none of the above e. all of the above
Dr. Doom Page 3 of 6 Consider the following typescript when answering questions 6-10 on this page. <w001ted@unixapps1:~ > /bin/pwd /common/users2/cse/w001ted <w001ted@unixapps1:~ > echo $PATH /bin:/usr/bin:/usr/ucb:/usr/xpg4/bin:. <w001ted@unixapps1:~ > alias script /bin/who <w001ted@unixapps1:~ > 6. If an executable shell script called runme exists in all of the directories of the path, which command will be executed by this command: $ runme a. /bin/runme b. /usr/bin/runme c. /usr/ucb/runme d. /usr/xpg4/runme e. runme in your current directory 7. If an executable shell script called script exists in all of the directories of the path, which command will be executed by this command: $ script a. /bin/script b. /usr/bin/script c. script in your current directory d. /bin/who e. /bin/ls 8. For the questions above, which of the following commands could you have used to determine which command would be executed? a. findcommand b. ls c. path d. which 9. If you d like to execute the command poweroff that is only available in /usr/sbin/, which of the following commands would work (assuming that you have appropriate permissions)? a. poweroff b. /usr/sbin/poweroff c. ~/poweroff e. none of the above 10. Which command would remove an alias that you had previously defined for who? a. rmalias who b. delalias who c. alias who d. unalias who e. c. and d. 11. Which of the following commands would list ALL of the files in a directory, including dot files? a. ls a b. ls d c. ls l d. ls x e. ls F 12. The pwd command will return the name of your current directory. What is pwd an acronym for? a. print which directory b. push working directory c. print working directory d. path of which directory e. process which directory
Dr. Doom Page 4 of 6 Consider the following typescript when answering questions 13-18 on this page. heartofgold@gandalf:~/hitchhikers> /bin/ls -l total 64 dr-xr--r-- 2 heartofgold hitchhikers 24 Sep 24 13:11 dir1 -rw----r-- 1 heartofgold hitchhikers 2938 Sep 24 13:51 arthur drwxr--r-- 2 heartofgold hitchhikers 8216 Sep 24 13:59 marvin -r-------- 1 heartofgold hitchhikers 18 Sep 24 13:37 trillian -rwxr-xr-x 1 heartofgold hitchhikers 176 Sep 24 13:51 zaphod 13. Which elements of the file listing above are directories? a. arthur b. marvin c. trillian d. zaphod e. a. and b. 14. Who is able to read the contents of the file arthur? a. user heartofgold b. anyone in group hitchhikers c. everyone (all) d. a. and c. e. a. and b. 15. What actions could you execute if you were currently in the directory dir1? a. create a new file b. read an existing file c. delete an existing file d. b. and c. 16. Currently, the file trillian is only readable by heartofgold. Which of the following commands would make it also readable by the group hitchhikers? a. chmod 444 trillian b. chmod g+r trillian c. chmod 404 trillian e. a and c. 17. If all of the elements of the listing that are not directories are files that contain shell scripts, which are shell scripts that could be executed by heartofgold? a. arthur b. marvin c. zaphod d. a. and c. 18. Which of the following commands would remove group read permission from file zaphod? a. chmod g-r zaphod b. chgrp zaphod c. chgrp read zaphod d. chmod g-x zaphod e. chgrp g-r zaphod 19. Which of the following commands would execute a file listing of your current directory and write that listing into a file named output. a. ls; output b. ls output c. ls > output d. ls && output e. c. and d. 20. Which of the following commands would tell you your current terminal emulation? a. echo TERM b. echo $TERM c. echo $TERM
Dr. Doom Page 5 of 6 Consider the following typescript when answering the questions on this page. serenity@paladin:~/firefly> /bin/ls -l total 64 -rw-r--r--1 serenity firefly 821 Sep 24 13:54 book -rw-r--r--1 serenity firefly 2938 Sep 24 17:51 inara -rw-r--r--1 serenity firefly 288 Sep 24 17:51 jayne -rw-r--r--1 serenity firefly 2918 Sep 24 17:51 kaylee -rwxr-xr-x1 serenity firefly 176 Sep 24 08:31 mal -rwxr-xr-x1 serenity firefly 143 Sep 24 08:31 river -rwxr-xr-x1 serenity firefly 189 Sep 24 08:31 simon -rw-------1 serenity firefly 45 Sep 24 12:32 wash -rw-rw-r--1 serenity firefly 841 Sep 24 13:54 zoe 21. Which of the following commands will produce a listing that includes the file mal? a. ls b. ls m* c. ls?a* d. ls mal* e. all of the above 22. Which of the following commands will produce a listing that includes the files inara and jayne? a. ls??a* b. ls [ij]???[a-g] c. ls *a* d. a. and c. 23. Which of the following commands will list ONLY the files jayne and kaylee? a. ls *y* b. ls?ay*e c. ls *e 24. How many files will be listed by this command: /bin/ls?a*l* a. 1 b. 2 c. 3 d. 4 e. 5 25. Which files will be listed by this command: /bin/ls??*o* a. book b. simon c. zoe 26. Which files will be listed by this command: /bin/ls {s,r,}i* a. simon b. inara c. river d. all of the above e. a. and b.
Dr. Doom Page 6 of 6 Consider this typescript and man page when answering the questions on this page. babylon5@paladin:~/b5> /bin/ls -l -rw-r--r--1 babylon5 b5 821 Sep 24 13:54 ivanova -rw-------1 babylon5 b5 2938 Sep 24 17:51 marcus -rw-r--r--1 babylon5 b5 288 Sep 24 17:51 sinclair babylon5@paladin:~/b5> umask 77 User Commands NAME cp - copy files cp(1) SYNOPSIS /usr/bin/cp [ -ip ] source_file target_file /usr/bin/cp -r -R [ -fip ] source_dir... target In the first synopsis form, neither source_file nor target_file are directory files, nor can they have the same name. The cp utility will copy the contents of source_file to the destination path named by target_file. If target_file exists, cp will overwrite its contents, but the mode (and ACL if applicable), owner, and group associated with it are not changed. The last modification time of target_file and the last access time of source_file are set to the time the copy was made. If target_file does not exist, cp creates a new file named target_file that has the same mode as source_file except that the sticky bit is not set unless the user is superuser; the owner and group of target_file are those of the user. If target_file is a link to another file, cp will overwrite the link destination with the contents of source_file; the link(s) from target_file will remain. In the second synopsis form, one or more directories speci fied by source_dir are copied to the directory specified by target. Either -r or -R must be specified. For each source_dir, cp will copy all files and subdirectories. -i Interactive. cp will prompt for confirmation whenever the copy would overwrite an existing target. A y answer means that the copy should proceed. Any other answer prevents cp from overwriting target. -r Recursive. cp will copy the directory and all its files, including any subdirectories and their files to target. -R Same as -r, except pipes are replicated, not read from. -p Preserve. cp duplicates not only the contents of source_file, but also preserves the owner and group id, permissions modes, modification and access time, and ACLs if applicable. The command will not fail if unable to preserve modification and access time or permission modes. If unable to preserve owner and group id, cp will not fail, and it will clear S_ISUID and S_ISGID bits in the target. cp will print a diagnostic message to stderr and return a non-zero exit status if unable to clear these bits. In order to preserve the owner and group id, permission modes, and modification and access times, users must have the appropriate file access permissions; this includes being superuser or the same owner id as the destination file. 27. Which of the following commands will copy the contents of one entire directory dir1 into a new identical directory dir2 (both in your current directory)? a. cp dir1 dir2 b. cp R dir1 dir2 c. cp r dir1 dir2 d. cp f dir1 dir2 28. Which of the following will copy ivanova onto sinclair without asking for confirmation? a. cp -i ivanova sinclair b. cp -I ivanova sinclair c. cp ivanova sinclair d. cp -p ivanova sinclair e. c. and d. 29. If the command $ cp -p sinclair valen is executed, which of the following shows the permissions of the new file valen? a. ---------- b. -rw-r--r-- c. -rwx------ d. -rw-r--rwe. unknown 30. If the command $ /bin/touch delenn is used to create a new file called delenn, which of the following shows the permissions of the new file delenn? a. ---------- b. -rw-r--r-- c. -rwx------ d. -rw-r--r-- e. unknown