The disk is full
An app stops saving. The error says no space left. Before anyone buys more disk, an engineer asks what is using it, packs the old files into one archive and moves them away. Then the app works again.
By the end of this lesson
Note
I can pack files, check the disk and fetch a file from the web.
Key words
- Archive: many files packed into one.
- Compress: to make a file smaller.
- Disk: where files are kept when the machine is off.
- Memory: where running programs keep what they are using.
- Download: to copy a file from the web to this machine.
Starter: what you already know
Note
Answer in your head. 1. Which command goes to your home folder? 2. What is a log? 3. Why do two small files sometimes take longer to send than one big one?
Before you start
Note
Press Start the lab on the bar at the top of this lesson. This lab is a whole Ubuntu machine of your own, so it takes a little longer to come up than a container. Each Run button types its command into the machine's terminal, one after another in the same session. If one says the machine is still starting, wait a few seconds and press it again. Where the lesson says Type this, the command never ends by itself or asks you something, so press Open terminal on the bar and type it yourself.
Pack and unpack
An archive packs files into one. unzip opens a zip. gzip squeezes one file and renames it with .gz, and gunzip undoes it. tar -czf packs a folder into a .tar.gz, and tar -tzf lists what is inside it. To unpack one, tar -xzf takes the same name.
cdShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
unzip test.zipShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
cat inside.txtShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
gzip testShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
gunzip test.gzShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
tar -czf projects.tar.gz projectsShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
tar -tzf projects.tar.gzShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Check
Tip
Which command packs a folder into one file, and which one lists what is inside it? Answer: tar -czf packs it, and tar -tzf lists it.
How full is the machine?
df -h shows each disk and how full it is, in sizes people can read (-h). du -sh * shows how big each thing in this folder is. free -h shows the memory.
df -hShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
du -sh *Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
free -hShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Fetch from the web
wget saves a file from a web address into the folder you are in. curl prints what an address returns, and -s hides the progress. The lab runs a small web server of its own at localhost:8000, so this works without the internet.
wget http://localhost:8000/report.csvShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
cat report.csvShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
curl -s http://localhost:8000/hello.txtShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Exit check
Tip
Answer without looking back. 1. What does -h do in df -h? 2. Which command saves a web file into this folder? 3. What does gzip do to the file name? Answers: prints sizes people can read; wget; adds .gz.
For teachers
Tip
This lesson is a small example of a lesson worked in a lab: the steps and the Run buttons are the lesson, and the lab is each student's own copy. This lesson is worked in a VM lab: each student has an Ubuntu machine of their own, and a Run types into its terminal and shows what it printed. Key learning points: 1. zip, gzip and tar pack and unpack. 2. df, du and free show what is using the machine. 3. wget and curl fetch from an address. Common mistake: unpacking into the folder they are in without looking first. Equipment: the lab and a browser. Tip: ask what would be in the archive before it is listed, and compare. The lab has no check and marks nothing; set a hand-in of your own if you want one. Copy it into your own module and change it, or build one from scratch with the Lab menu in the lesson builder.