Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

Everyday Linux 4: Archives, disk and the web

The whole lesson is here to read. Create a free account to run it in a live lab.

Virtual machine lab11 min read13 commands

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.

Command
cd

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Command
unzip test.zip

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Command
cat inside.txt

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Command
gzip test

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Command
gunzip test.gz

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Command
tar -czf projects.tar.gz projects

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Command
tar -tzf projects.tar.gz

Shown 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.

Command
df -h

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Command
du -sh *

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Command
free -h

Shown 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.

Command
wget http://localhost:8000/report.csv

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Command
cat report.csv

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Command
curl -s http://localhost:8000/hello.txt

Shown 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.

About this lab and its source: Everyday Linux commands lab: the thirty commands engineers type from memory

Teaching a class? Set these lessons for your students with marking and a lab for every student.