Linux commands: df

By

Published · Updated

Tagged: CLI

Learn how the Linux df command reports disk usage for your mounted volumes, with df -h for human-readable sizes and a path to check the volume it lives on.

The df command is used to get disk usage information. It tells you how big each mounted file system is, how much is used, and how much space is left.

Its basic form will print information about the volumes mounted:

Terminal output showing df command listing mounted filesystems with raw numerical values for size, used, and available space

Human-readable sizes with -h

Using the -h option (df -h) will show those values in a human-readable format:

Terminal output showing df -h command displaying disk usage in human-readable format with GB and MB units

-h uses powers of 1024, so 1G is 1,073,741,824 bytes. If you want powers of 1000, the way disk makers count, use -H:

df -H

That’s why a disk can look a bit smaller with -h than the size printed on the box.

Check the disk a folder lives on

You can also specify a file or directory name to get information about the specific volume it lives on:

Terminal output showing df dev command displaying disk usage information for the specific volume containing the dev directory

This is the quickest way to answer “how much space do I have left here?”:

df -h .

The . means the current folder.

Reading the output

On Linux, df -h prints something like this:

Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        59G  4.7G   51G   9% /

You might notice that Used plus Avail doesn’t add up to Size. On ext4, the default Linux file system, 5% of the blocks are reserved for the root user by default. That space isn’t shown as available to normal users.

Useful options on Linux

These are the options of GNU df, the one on most Linux distributions:

df -hT          # add a Type column (ext4, xfs, tmpfs...)
df -i           # show inodes instead of space
df -h -x tmpfs  # hide tmpfs file systems
df -h -t ext4   # only show ext4 file systems
df -h --total   # add a total line at the end

-x and -t can be repeated, for example df -h -x tmpfs -x overlay to hide both.

You can also choose exactly which columns to show with --output:

df -h --output=source,fstype,size,used,avail,pcent,target

The valid column names are source, fstype, itotal, iused, iavail, ipcent, size, used, avail, pcent, file and target.

Disk full but there’s free space? Check inodes

Every file uses an inode, and a file system has a fixed number of them. If you have millions of tiny files (cache folders, session files, mail queues), you can run out of inodes while df -h still shows free space. You get “No space left on device” anyway.

Check with:

df -i

If IUse% is at 100%, find the folder with all the small files and clean it up.

df and du don’t agree

du adds up the size of the files it finds. df asks the file system how much space is used. Usually they’re close, but not always.

The common cause is a deleted file that a process still has open, often a big log file. The file is gone from the folder, so du doesn’t count it, but its space is only freed when the process closes it. Until then df still counts it as used.

Restarting the process that holds the file (or the whole machine) frees the space.

df on macOS

macOS has the BSD version of df, and a few things are different:

On a Mac with APFS, several volumes share the same container, so you’ll see the same Size and Avail on more than one line. Check df -h / or df -h ~ to see the volume you care about.

If you want the GNU version on a Mac, install coreutils with Homebrew and run gdf.

The df command works on Linux, macOS, WSL, and anywhere you have a UNIX environment.

Want me to talk about your product? You can sponsor this site.

Related posts about cli: