Structure

Exercise 1: Answer

Write in words how you might speak the directory ~/foo/bar.

root slash foo slash bar

Exercise 2: Answer

In /Users/bill/sonnets, what is the home directory? What is the username? Which directory is deepest in the hierarchy?

home dir = users, username = bill, deepest directory = sonnets

Exercise 3: Answer

For a user with username bill, how do /Users/bill/sonnets and ~/sonnets differ (if at all)?

~/sonnets belongs to the superuser/root, /Users/bill/sonnets belongs to a user named bill

Making directories

Exercise 1: Answer

What is the option for making intermediate directories as required, so that you can create, e.g., ~/foo and ~/foo/bar with a single command?

-p

Exercise 2: Answer

Use the option from the previous exercise to make the directory foo and, within it, the directory bar (i.e., ~/foo/bar) with a single command.

mkdir -p ~/foo/bar

Exercise 3: Answer

By piping the output of ls to grep, list everything in the home directory that contains the letter “o”.

ls -a | grep o

Navigating directories

Exercise 1: Answer

How do the effects of cd and cd ~ differ (or do they)?

they don't differ, they both change the current directory to home directory

Exercise 2: Answer

Change to text_directory, then change to second_directory using the "one directory up" double dot operator ... If these are directories don’t exist by default, you could either create them or use some other directories that already exist in you system.

cd text_directory, cd ..

Exercise 3: Answer

From wherever you are, create an empty file called nil in text_directory using whatever method you wish.

cd text_directory, touch nil

Exercise 4: Answer

Remove nil from the previous exercises using a different path from the one you used before. (In other words, if you used the path ~/text_directory before, use something like ../text_directory or /Users/username/text_directory.)

../nil

Renaming, copying, deleting directories

Exercise 1: Answer

Make a directory foo with a subdirectory bar, then rename the subdirectory to baz.

mkdir ~/foo/bar, mv ~/foo/bar ~/foo/baz

Exercise 2: Answer

Copy all the files in text_files, with directory, into foo.

cp -r ../text_files foo

Exercise 3: Answer

Copy all the files in text_files, without directory, into bar.

cp -r ../text_files/ bar

Exercise 4: Answer

Remove foo and everything in it using a single command.

rm -rf foo

Summary

Exercise 1: Answer

Using a single command-line command, make a directory foo, change into it, create a file bar with content baz, print out bar's contents, and then cd back to your home directory.

mkdir foo && cd foo && touch baz > bar && cd

Exercise 2: Answer

What happens when you run the previous command again? How many of the commands executed? Why?

no commands are executed because it won't create the same directory again

Exercise 3: Answer

Explain why the command rm -rf / is unbelievably dangerous, and why you should never type it into a terminal window, not even as a joke.

force removes all files on the system

Exercise 4: Answer

How can the previous command be made even more dangerous? (This command is so dangerous you shouldn’t even think it, much less type it.)

by adding sudo to the beginning, anybody can use the command