Linux on call · Chapter 21 of 30
Disk and memory
By the end of this chapter you can see how full the disk is, find what is filling it, free the space safely, and read how much memory is really left. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.
- Part: Processes and the system
- 4 tasks
- Linux
- In the all labs plan
The first 2 chapters of Linux on call are free. This one comes with the all labs plan.
Why you need this
The disk alert went off again, and Ravi's list is in note.txt: find the biggest file, empty the orders log without deleting it, and keep only the two newest backups. Last time Bunty deleted the log the app was writing to. The disk stayed just as full until the app was restarted on Sunday.
df -h .
Filesystem Size Used Avail Use% Mounted on
overlay 1007G 128G 828G 14% /
Your numbers will differ: this lab machine has room to spare, but Ravi's alert fires at 90%. ls -l shows one folder at a time, and rm on a file that a program holds open frees nothing at all, as Bunty found out.
What you build: 4 tasks
Each task has tests. You write the code in the lab's editor and press Check.
- Task 1
Save the biggest file's path in biggest.txt
Find the biggest file in the chapter folder, so you know what is filling the disk.
1. Do this first, before you empty or delete anything.
2. Use du to see which folder is the biggest.
3. Use du with sort to list every file by size. Folders show up too, with their totals: skip them.
4. Save the path of the biggest file in biggest.txt, in the chapter folder. Write it from the chapter folder, like folder/name.
To pass: biggest.txt has the path of the biggest file (a file, not a folder), and nothing else.
- Task 2
Empty the orders log without deleting it
Empty logs/orders.log, but do not delete it. The app keeps this file open.
1. Run stat on logs/orders.log. Note its inode number and its size.
2. Use truncate to set the file's size to zero.
3. Run stat again. The inode is the same, and the size is 0.
To pass: logs/orders.log is still the same file (the same inode), with at most 100 bytes in it. Do not delete it and make a new file: a new file has a new inode.
- Task 3
Keep only the two newest backups
Delete the old backups, but keep the two newest ones.
1. Run ls -lt backups. It lists the newest file first.
2. Keep tapri-2026-09-30.tar.gz and tapri-2026-10-01.tar.gz.
3. Delete the three older backups with rm, one name at a time.
4. Run ls backups again to see what is left.
To pass: the backups folder has exactly these two files and nothing else.
- Task 4 · interview question
Interview: save a disk and memory report in health.txt
Interview question: how do you check the disk and the memory on a server? Save both reports in one file.
1. Run df -h and save its output in health.txt, in the chapter folder. Use >.
2. Run free -h and add its output to the end of health.txt. Use >>, so the first report stays.
3. Run cat health.txt. You see the disk table, then the memory table.
To pass: health.txt has the df -h report (with its Filesystem, Size, Used and Avail header) and the free -h report (with its Mem: line).
What you will learn
- df and du: how full each disk is, and what is using the space.
- Finding the biggest files: du with sort -h, and find -size.
- Emptying a file in place: why rm frees nothing while a program holds the file open.
- free: how much memory is really available.
More in Processes and the system
Build "Disk and memory" yourself
Tapri’s ordering app moves onto a Linux server, and the server is now yours to run. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.
The first 2 chapters of Linux on call are free. This one comes with the all labs plan.