LearnLinux FoundationsReading Files

df

df - a hands-on Linux lab on a real virtual machine.

Read a whole disk at a glance with df. The six columns, human units with -h, one filesystem by path, and the one df output that is identical on every machine. df is structure-only: your numbers and device names vary, so the drills teach the shape and the moves.

You have spent this module looking INSIDE files: printing them, paging them, counting their lines, measuring their bytes. This lesson zooms all the way out. Forget one file. How much room is left on the whole machine?

That is not a curiosity. It is the question that saves you at 3 a.m. when a service stops writing logs, a build fails with no clear error, or a copy dies halfway. The cause is often the same boring thing: the disk filled up. There is one command that answers it in a single line, and it is called df.

The black boxes in this lesson are a practice terminal: a safe sandbox that only checks the one command each step teaches, so you cannot break anything. df reads your REAL disk, so its numbers and drive names change from machine to machine. The outputs shown here are one real capture, kept as an example. On the live machine at the end of the module, you run df against your own disk and read your own numbers.

df is short for disk free. It reports how much space each filesystem on the machine has, how much is used, and how much is left. A filesystem is one formatted storage area the system can read and write, like your main drive or a plugged-in disk.

Notice the pairing with the last lesson. du, disk usage, measured the space taken by files and folders YOU point it at. df, disk free, measures the whole container those files live in. du looks at the luggage; df weighs the whole plane.

Before you read a single number, prove the command is really there. Every command ships with a built-in help screen, and df --help prints it: a usage line followed by a list of the options df understands. If that screen prints at all, df is installed and ready. Run it now:

df --help

prompt: student@linuxcamp:~$ answer: df --help output: Usage: df [OPTION]... [FILE]... Show information about the file system on which each FILE resides, or all file systems by default. hint: Type df, a space, then two dashes and the word help: df --help

That first line is the usage summary, df [OPTION]... [FILE]...: the square brackets mean optional, so you CAN hand df some options and a file, but you do not have to. The full help screen goes on to list every option df understands. Run df with nothing at all and it reports on every filesystem the machine has mounted. That is what you do next.

Run bare, df prints its sizes in 1-kilobyte blocks, which are accurate but hard on the eyes. The -h flag fixes that. -h stands for human-readable, and it rounds every number into friendly units: K for kilobytes, M for megabytes, G for gigabytes.

This is the form you will actually type. Ask the machine for its whole disk picture in human units:

df -h

prompt: student@linuxcamp:~$ answer: df -h output: Filesystem Size Used Avail Use% Mounted on devtmpfs 4.0M 0 4.0M 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 768M 428K 768M 1% /run /dev/nvme0n1p1 8.0G 7.1G 886M 90% / tmpfs 1.9G 411M 1.5G 22% /tmp hint: Add the -h flag between df and nothing else: df -h

Those exact numbers and drive names belong to the machine this was captured on. On YOUR machine the sizes, the percentages, and the device names (you might see /dev/vda1 instead of /dev/nvme0n1p1) will all be different. That is expected: df reads a live, real disk. What stays the same everywhere is the SHAPE, six labelled columns, and that shape is the whole lesson.

Every df -h line has the same six columns, left to right. Learn them once and you can read any machine's disk at a glance:

The one column your eye should jump to is Use%. In the capture above, the line for / reads 90%. That is the whole point of df: one glance told you the main drive is nearly full, long before anything broke.

A tmpfs line is a filesystem that lives in memory, not on a physical disk. It is normal to see several. When you are hunting for a full disk, the line that matters is almost always the one Mounted on /, your root filesystem.

Sometimes you do not want the whole list. You care about one place: where am I standing, or where is this file, and how full is THAT disk? Hand df a path and it answers for just the filesystem that path lives on.

Point it at the root of the whole tree, /, and keep the human units:

df -h /

prompt: student@linuxcamp:~$ answer: df -h / output: Filesystem Size Used Avail Use% Mounted on /dev/nvme0n1p1 8.0G 7.1G 886M 90% / hint: Same df -h as before, then a space and a single forward slash: df -h /

Again, the size, the percentage, and the device name are this machine's. Yours will read differently. What is worth memorising is the MOVE: df -h <path> collapses the whole list down to the one filesystem that holds that path. The header stays; only the relevant row prints.

One row, plus the header. By naming / you told df you only cared about the filesystem mounted there, so it dropped every tmpfs and memory line and showed you the single disk that matters. Swap / for any path, df -h /tmp or df -h . for wherever you are standing, and df reports the filesystem that path sits on. One honest wrinkle: only some machines give /tmp its own memory-backed tmpfs. On machines that do not, /tmp is just a folder on the root disk, so df -h /tmp prints the root filesystem's row with / under Mounted on. That is not an error; it is df telling you which filesystem really holds that path.

It is worth knowing what -h saves you from. Run df with NO flag and the same disk comes back in raw 1-kilobyte blocks: long, exact counts instead of the friendly K, M, and G. The header shifts to match: the Size column is relabelled 1K-blocks, and the free column is spelled out in full as Available. Same six columns, same disk, just harder on the eyes.

Run the bare form once so you feel the difference:

df

prompt: student@linuxcamp:~$ answer: df output: hint: Just the two letters and Enter, no flag at all: df

Bare df prints the same live, machine-specific values as df -h, only in raw 1-kilobyte blocks, so its numbers are not shown here and will differ on your disk. The lesson is not the counts, it is the CONTRAST: no flag gives exact blocks under a 1K-blocks header, while -h rounds those same figures into K, M, and G. That readability is why -h is the form you will almost always reach for.

Scaffolding off. No command is printed this time. You have every piece you need.

You are on an unfamiliar machine and you only care about one thing: how full is the root filesystem, the disk mounted at /? You do not want the whole list of filesystems, just that single one, and you want it in friendly units you can read at a glance.

prompt: student@linuxcamp:~$ answer: df -h / output: Filesystem Size Used Avail Use% Mounted on /dev/nvme0n1p1 8.0G 7.1G 886M 90% / hint: Combine the human-readable flag you learned with a single path. Think df, then -h, then the path /.

That is the everyday move. The -h flag gave you readable units, and the path / pinned the report to one filesystem. So you got the header plus a single row, with / under Mounted on, and nothing else. Your own sizes and device name will differ, but that shape, one header and one root row, is what you will see on any machine, and the command is exactly what a working engineer types. You combined a flag and a path from memory, which is the same recall the real machine will ask of you.

You earned this cheat sheet. Every row is a form of df you just ran:

And the six columns you can now read on any machine: Filesystem, Size, Used, Avail, Use%, Mounted on. When something breaks and you suspect space, df -h is the first command to type, and Use% on the / line is the first number to read.

df tells you a disk is full; it does not tell you WHAT filled it. That is du's job, from the last lesson. The pair works together: df -h finds the full filesystem, then du -sh * inside a suspicious folder finds the space hog. Disk free, then disk usage.

The practice terminal has shown you the shape of df. You have the six columns, the -h flag for readable units, a path to focus on one filesystem, and --help as the one output that never changes. Every one of those you typed yourself.

The Reading Files module ends with one real Linux machine, the reading-files capstone mission, and that is where you run df for real. A VM boots just for you, with its own live disk. It hands you objectives that use exactly what you practiced across this module: reading, paging, counting, and measuring files, and checking the disk they live on. One difference from here: the mission shows no commands. You read the objective, you recall the command, you type it. That recall is what makes it stick.

Finish the other Reading Files lessons, then go read a real disk for yourself.

Practice df in a real Linux terminal at The Linux Camp. Progress is verified automatically as you type commands on the machine.