Review
Last Week
What did we do in our last class?
- paths - absolute and relative
- input and output, downloading files, archiving/compressing and extracting/uncompressing
Special Symbols for Paths
What symbols represent the following directories? →
- the current directory
- up one directory (parent directory)
- up two directories
- root directory
- home directory
- directory you were previously in
Special Symbols for Paths
- . (dot) - the current directory
- .. (dot dot) - up one directory (parent directory)
- ../.. (dot dot slash dot dot) - up two directories
- / (slash) - root directory
- ~ (tilde) - home directory
- - (dash) - directory you were previously in
Root
- What’s the root directory? →
- What symbol represents it?? →
- the root directory is the top most folder or directory in a file system
- it contains all of the other directories and files
- think “Macintosh HD” on OSX
- or c: on Windows
- root is represented by “/”
- cd / will bring you to the root directory
Note About Root
We didn’t explicitly mention this in the last class, but:
- the root directory is not writable by the lab computer default user account
- consequently, if you’re in root, commands like mkdir, touch, etc… should fail
- How would I get to root again? →
Absolute Paths
What’s an absolute path?
- absolute paths are paths expressed as starting from root.
- /Users/professor/Desktop
- /Volumes
- you can get to an absolute path regardless of your current working directory
Relative Paths
What’s a relative path?
- relative paths are paths expressed as relative from the current working directory.
- current directory is /User; to get to home: professor
- current directory is /User; to get to Desktop: professor/Desktop
- you have to be in the directory that you’re assuming to be current for this to work.
Relative and Absolute
Tell me how to create these directories in my home folder →
- a directory called myprojects
- within that, two directories called lab1 and lab2
- and finally, in lab1, create a directory called output
This should result in:
- myprojects
- myprojects/lab1
- myprojects/lab2
- myprojects/lab1/output
Relative and Absolute Path Questions
- From /Volumes, change to the lab1 directory that was just created
- In /Volumes: cd ~/myprojects/lab1
- From home directory, what’s the relative path to output?
- In home: myprojects/lab1/output
- From home directory, what’s the absolute path to output?
- In home: /Users/professor/myprojects/lab1/output
- From output, what’s the relative path to lab2?
- In myprojects/lab1/output: ../../lab2
Relative and Absolute Path Questions Continued
- From output, what’s the absolute path to lab2?
- In myprojects/lab1/output: /Users/professor/myprojects/lab2
- From lab2, what’s the relative path to output?
- From lab2, what’s the absolute path to output?
- In lab2: /Users/professor/myprojects/lab1/output
- How do I print/output text to the screen? →
- How do I clean up / remove the text from the screen? →
Downloading Files
- How do I download a file and display its contents on my screen with one command? →
- How do I download a file and save it to a file with a specified name? →
- curl -o filename.txt someurl.com
- what’s the -o flag its following argument for?
…it specifies the name of the file to save your download to.
Archiving and Compressing Files
- How do I archive an entire directory into a single file? →
- tar -cvf archivename.tar dirname
- How do I compress a file? →
Extract and Uncompress
- How do I uncompress a zip (.zip) file? →
- How do I extract files from a compressed archive (.tar.gz)? →
- unzip filename.zip
- tar -xvf filename
Activity: Drills!
Entering commands flash cards x 3 (use set 2)
We’ll do this together, then try downloading it yourself:
- Download drills.py to the home directory
- Type python drills.py
- When prompted for a number, enter 2
- CTRL-C quits
Summary Part 1
(brackets - []’s - denote arguments that you must supply; the brackets are not part of the command, so don’t type them out)
- echo [something to print to the screen]
- clear
- curl [url of file to downlaod]
- curl -o [name of file to download to] [url of file to download]
- unzip [name of file to unzip]
- tar -xvf [name of file to extract and uncompress]
- tar -cvf [name of archive] [name of directory to archive]
- gzip [name of file to compress]
Lab
Review
- Type each command (with arguments and flags) exactly
- Only press <ENTER> when instructed…
- <TAB>, <ENTER>, <UP>, <DOWN> are the actual keys!
- Paste answer or output below the dashed line (————)
Activity: Everything We’ve Learned So Far
Entering commands flash cards x 3 (use sets 1 and 2)
We’ll do this together, then try downloading it yourself:
- Download drills.py to the home directory
- Type python drills.py
- When prompted for a number, enter 12
- CTRL-C quits