# Homework 1 Solutions ## Problem 1 1. Tux wants to go from /tux/igloo/puzzles/portal to /frank/igloo/puzzles/portal. How does he do that? Show how to do this two different ways. One way should use absolute file paths, and one should use relative file paths. relative path: cd ../../../frank/igloo/puzzles/portal absolute path: cd /frank/igloo/puzzles/portal 3. Tux is in the root directory /, with subdirectories tux and igloo. He cd’s to the parent directory two times. Where does he end up? Tux ends up in his root directory. The root directory's parent happens to recursively point to itself. 5. In your homework directory, there will be a folder called penguins. Explore the directory a bit! Tux wants to know what the structure of the penguins directory is, and asked you for a list of all the file paths and folder paths in penguins. ``` penguins penguins/march_of_the_penguins penguins/march_of_the_penguins/antarctica.jpeg penguins/march_of_the_penguins/emperor_penguins.png penguins/happy_feet penguins/happy_feet/antarctica.flac penguins/happy_feet/mumble.mkv penguins/madagascar penguins/madagascar/kowalski.png penguins/madagascar/skipper.png penguins/madagascar/rico.png penguins/madagascar/private.jpg penguins/madagascar/TOP_SECRET penguins/madagascar/TOP_SECRET/smile_and_wave.txt ``` 4. Any tree that gets them all accurately is fine. ## Problem 2 ``` man ls ls -a ls -lh cd penguins cat puzzles.txt cd ~ pwd touch ~/.bashrc vim ~/.bashrc source ~/.bashrc shhh mkdir temp cd temp touch history.txt touch historic.txt rm historic.txt cd .. rm -rf temp touch history.txt history 16 history 17 > history.txt # or whatever ``` ## Problem 3 ``` vi puzzles.txt i "Muffy's List of Puzzles: ESC :set number dd 8j ww daw :%s/puzzle//g :wq ``` 9. 31 substitutions were made. (Would also accept 37, if student did both "Puzzle", and "puzzle") 10. Command mode is a vim mode for using keyboard commands, allowing you to move the cursor and cut/copy/paste text, among other things. The vi editor opens in command mode. Insert mode is a vim mode for inserting text in a file. To switch from command mode to insert mode, you use the `i` key. To switch from insert mode to command mode, you use the `ESC` key. 1. To quit without saving, we can force quit with `:q!`. ## Problem 4 1. What happens when you run mv penguins.txt penguins.pdf (you may assume that penguins.txt is a text file)? What does this do to the file? What is the filetype of the new document? 2. What happens when you try to mv a parent directory into its child? Why do you think this is the case? Assume you have two sibling folders, penguins and puzzles. They are normal folders (not symlinks). a. What is the difference between mv penguins/ puzzles, mv penguins puzzles, and mv penguins/* puzzles? `mv penguins puzzles` moves `penguins` into `puzzles` `mv penguins/ puzzles` moves `penguins` into `puzzles`, with the additional semantic difference of directly specifying that penguins is a directory. Moving something that is not a directory while adding / causes a "not a directory" error is penguins is not a directory. `mv penguins/* puzzles*` moves the contents of `penguins` to `puzzles. ` b. What about mv penguins puzzles, when puzzles does not currently exist? If `puzzles` does not exist, `penguins` will be renamed to `puzzles`. c. What happens when you try to make a puzzles file when there is already a puzzles directory? There will be an error. `touch` does not create a file when a directory is present, instead changing the edit time, and we were looking for an actual attempt to create a file. 3. You are in your root directory, and you are looking for a file called black white.txt, but you can’t remember what directory it’s in. What command do you run to figure out where it is? find ~ -name "black white.txt" ## Problem 5 | Starting State | Command | Ending State | | -------------- | -------------- | ------------ | | rw-r--r-- | chmod 777 | rwxrwxrwx | | rw-r--r-- | chmod 660 | rw-rw---- | | rw-r--r-- | chmod 100 | --x------ | | rw-r--r-- | chmod 640 | rw-r----- | | rw-r--r-- | chmod +x | rwxr-xr-x | | rw-r--r-- | chmod a+x | rwxr-xr-x | | rwxrwxr-- | chmod u+w,g-w | rwxr-xr-- | | rwx--x--x | chmod g+rw,o=r | rwxrwxr-- | | rw-r--r-- | chmod 1750 | rwxr-x--T | | rw-r--r-- | chmod 1751 | rwxr-x--t | | rw-r--r-- | chmod 3740 | rwxr-S--T | | rw-r--r-- | chmod 7777 | rwsrwsrwt | 1. see table above 2. `ls -l` 3. * file. read write permissions for the owner, read permissions for everyone else. * directory. read/write/execute permissions for the owner, read/execute for the group, read for everyone else. * symbolic link. read/write/execute permissions for the owner, no permissions for anyone else, further permissions can be found by running ls -le. 4. `chmod 600` `chmod 440` 5. `chmod 007` 6. If you don't have read access to the parent directory, then you only can't ls that parent directory. If you don't have execute access to the parent directory, then you can't `cd` to it from the parent's parent or from the child directory. Access to the child directory, however, is unaffected (it just may be trickier getting there).