# Homework 1 Please answer all questions with a few sentences unless otherwise stated. You can use any text editor to write down your answers, but they must be written in [**Markdown** format](https://guides.github.com/features/mastering-markdown/). We recommend using [HackMD](https://hackmd.io) for editing Markdown files and [md2pdf](https://md2pdf.netlify.com/) to convert them to a pdf. When you are finished, submit a pdf of your answers to Gradescope. Some problems will involve navigating around directories and/or interacting with files. You will be performing these actions in the CS6 homework environment which you can access by running `cs6-work hw1` on a department machine. Problem parts that require this special environment will say so. If you get a "command not found" error, make sure the setup from hw0 is done first. ## Problem 1: Navigating Files Tux the Penguin is new to the terminal, and they were hoping you could help them navigate so they could find their igloo. Enter all your answers in a markdown file. We will call this file `hw1.md`. This link might be helpful. The `man` command may also be helpful. https://files.fosswire.com/2007/08/fwunixref.pdf Help Tux change directories to get where they want to go, and enter your commands into `hw1.md`. 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. 2. Tux is in the root directory `/`, with subdirectories `tux` and `igloo`. They `cd` to the parent directory two times. Where does he end up? 3. In your CS6 homework environment, 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 asks you for a list of all the file paths and folder paths in `penguins`. 4. Tux has a list of file paths for a folder called `puzzles`, but now they have trouble visualizing the tree structure of the directory. Help them out by drawing a tree (preferably by hand), taking a photo of it, and submitting it with your assignment on Gradescope. ``` puzzles/jigsaw puzzles/jigsaw/beak.html puzzles/jigsaw/feathers.css puzzles/jigsaw/flipper.js puzzles/jigsaw/cabin.jar puzzles/crosswords puzzles/crosswords/thursday.sql puzzles/crosswords/tuesday.tar puzzles/crosswords/wednesday.csv puzzles/crosswords/weekends puzzles/crosswords/weekends/sunday.ai puzzles/crosswords/weekends/saturday.py puzzles/crosswords/monday.wav puzzles/sudoku puzzles/sudoku/puzzle1.txt puzzles/sudoku/puzzle3.har puzzles/sudoku/puzzle2.md ``` ## Problem 2: Basic Commands Tux is still trying to learn their way around the terminal, so you decide to help walk them through a few things and show him the metaphorical ropes. You will need to perform these actions in the CS6 homework environment. Your starting point should be `~/<username>/hw1/problem2` in the environment. The only things that you will **need to include** in your answer document are detailed in **part 18**. 1. Type `man ls` to show Tux the man page for the `ls` command. Hit q to quit the man page. Feel free to read the man page for any commands you learn here. 2. List all the current directory contents for Tux, including files that begin with a dot (.). 3. Tux wants to see the directory contents, but he also wants to see the size of all the files within. List all the directory contents in long format, and make sure that the filesizes have acronyms denoting their denominations (ie. bytes, kilobytes, etc). 4. Change directories (`cd`) into `penguins`. 5. Type `cat p` and hit the tab key in order to autocomplete `puzzles.txt`. The autocomplete feature is incredibly helpful when you have directories and files with long names that you can't quite recall. 6. `cd` into your home directory. 7. Print the current working directory to see what Tux's home directory is. 8. In order to avoid having to manually type out a long string of directories again, set up an alias. Create a file in your home directory called `.bashrc` by executing `touch ~/.bashrc`. Then vim into the file and add the following line: `alias shhh="cd ~/hw1/problem2/penguins/madagascar/TOP_SECRET"` Then load that alias by executing `source ~/.bashrc`. 11. Change directories to `TOP_SECRET` using your alias. 12. Make a directory called `temp`. 13. Change directories into `temp`. 14. Create two files called `history.txt` and `historic.txt` using the `touch` command. 15. Remove `historic.txt` using the `rm` command. 16. `cd` to temp's parent directory. 17. Remove temp and its contents using the `rm` command. (hint: if you hit an error, check the man page) 18. Create `history.txt` again. 19. Run `history 16` to print what your last 16 commands are to the terminal. 20. Run `history 17 > history.txt`. This will redirect the history command to output the last 17 commands into history.txt, instead of printing it to the terminal. You might need to use a larger number to ensure that you get all of the commands you've executed for problem 2. Copy the contents of `history.txt` into your `hw1.md`. ## Problem 3: vim Muffy the penguin comes to you and asks for help making some edits to her puzzle file using her terminal. Unfortunately, Muffy cannot use a mouse with her flippers, so you will have to make these edits without ever touching the mouse. You decide that this is a job for vim. You will need to perform these actions in the CS6 homework environment. These guides to vim and vim modes might be helpful for this problem. * https://www.cs.cmu.edu/~15131/f17/topics/vim/vim-cheatsheet.pdf * https://vim.swaroopch.com/introduction.html * https://vim.swaroopch.com/modes.html * https://www.linux.com/learn/vim-tips-basics-search-and-replace 1. Open `problem3/puzzles.txt` in vim. 2. Enter insert mode and type "Muffy's List of Puzzles: " into the first line. 3. Muffy has some very specific edits she wants to make on certain line numbers. Enter a command that allows her to see the line numbers in the file. 4. Muffy Doesn't like brain teasers, so delete line 6 using a vim command. 5. Move the cursor eight lines down, and move the cursor to the third word without using the arrow keys or the letter keys h, j, k, and l. 6. Delete that third word for Muffy without using the delete key, backspace key, or x key. 7. Muffy already knows that these are all puzzles. Remove all instances of the word "puzzle" from the file. How many edits were made? 8. Save and quit the file. 9. In your answer document, list all the commands that you used in order to accomplish the bullets for this problem, as well as the number of edits made to remove 'puzzle' from the file. 10. In your answer document, type out an explanation of the insert and command mode, the use of each, and how to switch between them. 11. Also put down the command you would use if you wanted to quit the file without saving. ## Problem 4: Thaddeus waddled up to your desk, with a small markdown file in his flippers. He squawked a greeting, and placed the file in front of you. It contains these questions. You might find the `find` command useful for this problem. 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? 3. 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`? b. What about `mv penguins puzzles`, when `puzzles` does not currently exist? c. What happens when you try to make a `puzzles` file when there is already a `puzzles` directory? 5. 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? ## Problem 5: chmod Nicolette the penguin wants to organize a puzzle game where her friends all have different information and files that they are allowed to read for the game. Nicolette came to ask you for help with the file permissions! | Starting State | Command | Ending State | | -------------- | -------------- | ------------ | | rw-r--r-- | chmod 777 | rwxrwxrwx | | rw-r--r-- | chmod 660 | | | rw-r--r-- | chmod 100 | | | rw-r--r-- | chmod 640 | | | rw-r--r-- | chmod +x | | | rw-r--r-- | chmod a+x | | | rwxrwxr-- | chmod u+w,g-w | | | rwx--x--x | chmod g+rw,o=r | | | rw-r--r-- | chmod 1750 | | | rw-r--r-- | chmod 1751 | | | rw-r--r-- | chmod 3740 | | | rw-r--r-- | chmod 7777 | | 1. Fill out the table above and add it to your answer document. To get the table in your `hw1.md` you can copy the table above from the source Markdown file, or you can use [this handy online tool](https://www.tablesgenerator.com/markdown_tables) to generate the table for you. 2. How would you check the permissions on all the files in your current directory? 3. What permissions do these strings indicate? * `-rw-r--r--` * `drwxr-xr--` * `lrwx------+` 4. Nicolette wants to make sure that her `/answers` directory cannot be seen or written (no execution needed) to by anyone but her, the creator of that directory. She also wants to make sure that users in her moderator group are the only people (besides herself) who can read `/games/important/puzzle_mods.pdf`. What commands should she run? 5. What command would Nicolette run if she wants all users _except_ for her and the moderators group to be able to read, write, and execute `puzzles.py`? 6. What happens when you have read permissions for the `/games/important` directory, but NOT for `games`? What happens when you have execute permissions for the `/games/important` directory, but NOT for `games`? ## Handing In For this homework please hand in your .md file as a .pdf through Gradescope.