CIS 90 - Spring 2014 - PRACTICE TEST 2 - 30 points HONOR CODE: This is a practice test and you may work with others on it. However on the real test you must work alone. Submit the practice test even though it's not graded to verify you know how to do it correctly. Feel free to compare and discuss answers to the practice test on the forum. NAME: --> please replace this text with your name <-- INSTRUCTIONS: Download or copy and paste this page from your web browser into a text file on your computer. Don't use a word processor like MS Word! Instead use a text editor like Notepad (Windows) or TextWrangler (Mac) to add your answers to the questions below. This test should be completed using the Sun-Hwa system only. Log into Opus first then ssh into Sun-Hwa. The Sun-Hwa system will not be available when the real test starts. For questions with a *** you will be expected to do the requested operation in addition to answering the question. When grading, the instructor will check your answers and verify the operations were successfully completed. For questions not marked with a *** it may still be helpful to use Sun-Hwa to check your answers. [ ]'s are used to indicate the directory you should be in to do an operation. This will be your starting point for any relative pathnames. Please KEEP YOUR ANSWERS TO A SINGLE LINE ONLY and preserve the tags, e.g. "A1)", "A2)", etc. used to label the answers. Note to instructor: - Create student and extra accounts (Sun-Hwa) - Run setup-test2 P2 (Sun-Hwa) - Remove /etc/nologin (Sun-Hwa) [ ------------------------------------------------------------ ] [ Troubleshooting (1 point each) ] [ ------------------------------------------------------------ ] Instructions: Login to Sun-Hwa from Opus using just: ssh sun-hwa Q1) *** Before doing anything else run the flag command. What is the output from the flag command? A1) Q2) There is some serious trouble with your Sun-Hwa account that you need to troubleshoot and repair. Many of the commands we learned, such as ls and cat, no longer work. What EXACTLY is the problem? Be specific as to why this problem is occurring. A2) Q3) *** Once you have identified the problem, what single command will resolve the issue so all the commands work again? A3) Note: To confirm your fix run ./checkfix in your home directory. If you get stuck and can't fix this problem then use the forum to discuss the issue and get a solution. Q4) Benji (user simben90) needs your help. He has a directory named activities/ in his home directory. As the owner he has read and write permissions on each file in this directory yet he is unable to delete any of them. He really wants to get rid of the file named "marking" but he gets this error every time: [simben90@sun-hwa ~]$ rm activities/marking rm: cannot remove `activities/marking': Permission denied What single command can Benji use from his home directory to fix the problem? (feel free to examine his activities/ directory) A4) [ ------------------------------------------------------------ ] [ Managing files (1 point each) ] [ ------------------------------------------------------------ ] Instructions: Explore the LOCKED/ and Islands/ directories in your home directory. In the LOCKED directory is another directory named stuff/. In stuff/ you will see some directories named after oceans and some files named after islands. The next few questions guide you through reorganizing your home directory. Q5) *** [From your home directory] What single command "unlocks" your LOCKED/ directory so you can do a long recursive listing of it? A5) Q6) *** [From the Islands/ directory] What single command will move (not COPY) the CONTENTS of the stuff/ directory (but not the stuff/ directory itself) to the Islands/ directory? (Be careful to not change the contents of the files which contain custom information) A6) Q7) *** [From the Islands/ directory] What single command MOVES the Bahamas, Bermuda and Turks_and_Caicos files into the Atlantic/ directory? A7) Q8) *** [From the Islands/ directory] What single command MOVES the Bora_Bora, Easter_Island and Vanatu files into the Pacific/ directory? A8) Q9) *** [From the Islands/ directory] What single command copies the Arctic/ directory and the three island files in it from the TOP OF THE FILE TREE to the Islands/ directory? A9) Q10) *** [From your home directory] What single command removes the stuff/ directory from LOCKED? A10) When finished you can compare your work with Benji's below. They should match exactly. If you need to start over you can use ./restore to put your home directory back to the original state. [simben90@sun-hwa ~]$ tree LOCKED/ LOCKED/ 0 directories, 0 files [simben90@sun-hwa ~]$ tree Islands/ Islands/ +-- Arctic ¦   +-- ATOW1996 ¦   +-- Faeroe_Islands ¦   +-- Spitsbergen +-- Atlantic ¦   +-- Bahamas ¦   +-- Bermuda ¦   +-- Turks_and_Caicos +-- Pacific +-- Bora_Bora +-- Easter_Island +-- Vanatu 3 directories, 9 files [simben90@sun-hwa ~]$ [ ------------------------------------------------------------ ] [ Permissions (1 point each) ] [ ------------------------------------------------------------ ] Instructions: Review the contents of the readme file in your home directory to find the permissions to use in this step. Q11) *** [From your home directory] What single command changes the permissions on your Islands/ directory and its sub-directories (Artic/, Atlantic/, Pacific/) to what is specified in your readme file? A11) Q12) *** [From your home directory] What single command changes the permissions on all your island files (e.g. Bora_Bora, Bermuda, ..., etc.) to what is specified in your readme file? A12) Q13) *** What single command would automatically strip the following permissions from future files and directories when they are created? (test your answer on Sun-Hwa) For user strip nothing For group strip the write permission only For others strip read, write and execute permission A13) Q14) What are the permissions, in NUMERIC format, on /dev/tty5? A14) Q15) *** Set the umask setting to 237 and copy the hidden tar file in your home directory to backup.tar. What are the permissions on backup.tar? A15) [ ------------------------------------------------------------ ] [ Finding things (1 point each) ] [ ------------------------------------------------------------ ] Instructions: Restore your umask settings to 022. Q16) There is a file in the /etc directory named passwd. This file has information on all user accounts including usernames, UIDs, first and last name, etc. What is the absolute pathname of this file? A16) Q17) *** [From your home directory] There is a large file full of cities in the /opt branch that belongs to Desmond Hume. Locate this file and examine it. Each line has several fields separated by ":" characters. The first line is the header which has the name of each field. What command could you use to create a symbolic link to this file in your home directory named "cities"? A17) Q18) *** [From your home directory] The huge cities file has random words in the last two fields of each line. Some of these random words are actually first and last names of CIS 90 students. Find your city by finding the line containing your first and last name. What single command, using your cities symbolic link as the argument, will locate your line? A18) Q19) The first field of the line with your name has your city. What city did you get? A19) Q20) *** Now search the /opt branch for a file named after your city. Create a hard link to this file in your home directory named mycity. Add execute permissions to mycity and run it using ./mycity. What does mycity output when you run it? A20) Q21) *** Every CIS 90 student was assigned a different city file. The first, second and fourth lines of each city file are identical. Given that, what command can you use to find all the city files in the /opt branch? (your command must discard any permission error messages) A21) Q22) Who is the owner of your city file? A22) [ ------------------------------------------------------------ ] [ Input/Output (1 point each) ] [ ------------------------------------------------------------ ] Q23) *** [From your home directory] What pipeline command would output the first line of all your island files in Island/ and mail them to yourself and rsimms (on Sun-Hwa) with a subject of "Q23"? A23) Q24) *** What command would save the value of your PATH variable in a file named PATH.bak? A24) Q25) *** What command would print a SORTED list of the names of the Lost characters (e.g. Kate Austen, Jack Shephard, etc.) who have accounts on Sun-Hwa? A25) Q26) *** [From your home directory] There is a file named "math" in your home directory containing a mathematical expression to solve. Build a pipeline using only the cat, bc, tee and mail programs. The pipeline should: a) calculate the expression in math b) save the result to a file named "answer" c) mail the answer to yourself and rsimms (on Sun-Hwa) with a subject of "Q26". What single pipeline command does all this? A26) [ ------------------------------------------------------------ ] [ Six steps of the shell (1 point each) ] [ ------------------------------------------------------------ ] Q27) After issuing the following commands, how many lines would the file nums have and why? echo 5 > nums echo 4 >> nums echo 3 > nums echo 2 >> nums echo 1 > nums cat nums | wc -l A27) Q28) After issuing the following commands, how many lines would the file nums have and why? echo 5 > nums echo 4 >> nums echo 3 >> nums echo 2 >> nums echo 1 >> nums sort nums > nums A28) Q29) If Benji ran these commands: PATH=/bin:/usr/bin/:/usr/local/bin:/home/cis90/simben/bin flag When the flag command above is handled by the shell, how many directories must the shell search to find that command? A29) Q30) On Sun-Hwa, what is the absolute pathname of the DIRECTORY containing the wget command? A30) [ ------------------------------------------------------------ ] [ Extra credit (1 point each) ] [ ------------------------------------------------------------ ] Q31) *** For the names of the cities assigned to students for this test, what single pipeline command would: a) output a count of these city names to your screen b) record the city names in a file named citylist c) discard any permission errors (hint: the basename command may be helpful) A31) Q32) *** What two commands would allow you to run checkfix and mycity, from anywhere, without having to put the "./" in front of them? (use the ; metacharacter to separate the two commands in your answer) A32) Q33) What are the FULL (4 digit) permissions, in numeric format, on the "umount" command? A33) [ ------------------------------------------------------------ ] [ Submit this test ] [ ------------------------------------------------------------ ] When finished, leave your home directory intact. Copy and paste this completed test into a text-only email with NO attachments to: rsimms@oslab.cabrillo.edu @oslab.cabrillo.edu CONFIRM on Opus that your email was successfully sent and that your work is READABLE using the mail command.