Due: Tue. 02/17 at 11:59PM
Overview
In this exercise, you will practice navigating and modifying files in a complex directory structure. You will repeat exercises similar to this throughout the course of the semester. Over the course of the semester, the exercises will become slightly harder. The directory structure you work with is semi-randomly generated, so each student will receive a different ones each week to work with.
Receiving your exercise
You will generate a new directory structure to work with each time you
complete this exercise. There is a python script in the /home/ckazer/public
directory that you can execute to create a semi-random directory structure.
Navigate to where you would like to put the exercise files, and then run
$ python3 /home/ckazer/public/cs14/exercises/navigation/make_dir_structure_easy.py
Rather than copy-pasting this command, try typing it out using tab completion,
or using CTRL+r to search for it in your command history.
Follow the prompts to generate your exercise. This will create a directory
called treenav/.
Then use scp (or rsych) to copy the files to your cs14vm. scp works
similarly to cp except that you must specify both the host you are copying
from/to and the file/directory on that host.
So, to copy a directory recursively from the CS Network to your cs14vm, you would use
$ scp -r <source_directory> cs14vm:<destination>
Once you have copied the exercise to your cs14vm, you may remove the copy
that exists on the CS Network. As always, be careful using the command
rm -rf because it permanently deletes files without prompting for
confirmation.
$ rm -rf treenav/
Using asciinema
For this exercise, you must submit one or more asciinema recordings of you completing the exercise, as evidence of completing the assignment from the command line.
You can start an asciinema recording called naviagtion.cast as follows:
$ asciinema rec navigation.cast
Use Ctrl+d or enter the command exit to stop recording. If you record your
work in multiple sessions, give each recording a different name. E.g,
navigation_pt1.cast, navigation_pt2.cast, navigation_pt3.cast.
|
Warning
|
asciinema essentially functions as a "keystroke logger". You should
not enter any sensitive information, like passwords or other personal data,
while using it.
|
Completing the exercise
To begin with, there are three files you must find within treenav/:
-
re-name_me.txt -
remove_me.txt -
copy_me.txt
Each of the files contains instructions about what to do with the file. Use
cat to read their contents and perform the necessary operations.
Reminders
-
USE TAB COMPLETION!
-
press tab after writing a command and partially completing the name of a file or directory to auto-complete the name, assuming it is unique.
-
press tab multiple times to display the possible valid completions of a command, file, or directory if there is more than one option.
-
-
pwd-
If you don’t know where you are in the directory structure, use
pwdto "print the working directory" of where your terminal is currently.
-
-
ls-
lswith nothing after it will show the contents of the current working directory. -
lswith the name of a directory will show the contents of that directory, e.g. if your current directory contains another directory calledcs14/, thenls cs14/will show the contents ofcs14/.
-
-
cd-
cdwith nothing after it will return you to your home directory. -
You can use
cdto jump multiple directories at once, e.g.cd path/to/subdirectory. This works with tab completion! -
Use
cd ..to go back up a directory. This can be done multiple times at once, e.g.cd ../../../.
-
-
rm-
rm file_namewill attempt to deletefile_name -
Be careful! Files and directories removed with
rmgenerally cannot be recovered.
-
-
mv-
mvcan be used both to move files/directories and rename files/directories. -
mv a_file b_filechanges the name ofa_filetob_file -
mv a_file sub_dir/movesa_fileintosub_dir, keeping the namea_file. -
mv a_file sub_dir/b_filemovesa_fileintosub_dirAND changes its name tob_file.
-
-
cp-
cp a_file b_filecopies the contents ofa_fileintob_file. -
cpworks across directories. E.g.,cp a_file ../b_filewill create a copy ofa_filethat is one directory up calledb_file.
-
-
tree-
Use
tree .to print the directory tree of the current directory and all of its sub-directories. -
tree /will print the directory structure of your entire file system!
-
-
find-
findis a complex command with many options and functions! It’s easiest to start with a simple set of options and learn the others as you need them. -
To find a file whose name you know within a directory structure, you can use the following command:
find <base_directory> -name <file_name> -type f.<base_directory>is the directory where you want to search,<file_name>, is the name of the file, and-type fspecifies that you are looking for a file (rather than a directory).
-
Submitting the exercise
Once you are done, ensure that a directory named
/local/submissions/exercises/navigation04
exists on your cs14vm. Copy your modified directory structure and asciinema
recording to that directory (using cp -r). The instructor will copy your
exercise directly from that directory at the due date.