opscape

Disks and filesystems

df

Report how much space is used and free on mounted filesystems.

df [OPTION...] [FILE...]

8 of 9 examples run in Debian 13.7 on 2026-10-31 · coreutils 9.7-3 · manual: df(1)

df (disk free) shows, for each mounted filesystem, its size, how much is used, how much is available and where it is mounted. Given a path, it reports only the filesystem that holds that path, which is the quickest answer to "is there room to write here?".

-h makes the numbers readable, -T adds the filesystem type, and -i switches from blocks to inodes. A filesystem can run out of inodes (one per file) while plenty of space remains, which happens with millions of tiny files, and writes then fail with "No space left on device" all the same.

On a real machine, plain df -h lists every mount, including many small virtual ones; df -h -x tmpfs -x devtmpfs trims the list. The examples below name a path, because this sandbox is a container and its full mount list would describe the build server rather than anything useful. The container's root is an overlay filesystem, so that is what df reports for . here.

Examples

Free space where you are

df -h .
explain
output
Filesystem      Size  Used Avail Use% Mounted on
overlay         884G  436G  449G  50% /

One line for the filesystem holding the current directory. Avail is what you can still write; Size minus Used is often larger than Avail because ext4 and others reserve a share for root.

Exact numbers

df .
explain
output
Filesystem     1K-blocks      Used Available Use% Mounted on
overlay        926686080 456392448 470293632  50% /

Without -h, sizes are in 1 KiB blocks, better for scripts and comparisons.

Show the filesystem type

df -hT . /dev/shm
explain
output
Filesystem     Type     Size  Used Avail Use% Mounted on
overlay        overlay  884G  436G  449G  50% /
shm            tmpfs     64M     0   64M   0% /dev/shm

-T adds a Type column: overlay for the container's root, tmpfs for /dev/shm, which lives in memory. Two paths give two lines.

Check free inodes

df -i .
explain
output
Filesystem        Inodes   IUsed     IFree IUse% Mounted on
overlay        948865491 8278051 940587440    1% /

-i reports inodes instead of blocks. If IUse% is near 100% you cannot create files even though space remains; look for directories with huge numbers of tiny files.

Choose the columns

df --output=target,fstype,size,avail,pcent -h /dev/shm
explain
output
Mounted on Type   Size Avail Use%
/dev/shm   tmpfs   64M   64M   0%

--output picks and orders the columns, which is easier to parse than the default layout.

Use the percentage in a script

use=$(df --output=pcent /dev/shm | tail -1 | tr -dc '0-9')
if [ "$use" -ge 90 ]; then echo "disk almost full: $use%"; else echo "ok: $use% used"; fi
output
ok: 0% used

--output=pcent prints a header and one value; tail drops the header and tr -dc keeps only digits, giving a number the shell can compare.

Which filesystem holds a file

df -h data/users.csv
explain
output
Filesystem      Size  Used Avail Use% Mounted on
overlay         884G  436G  449G  50% /

Any path works; df reports the filesystem that contains it. Before writing a big file somewhere, check that path rather than guessing which disk it is on.

A path that does not exist

df -h /nonexistent
explain
outputexit 1
df: /nonexistent: No such file or directory

df needs an existing path to find the filesystem, and exits with 1 otherwise.

The full mount list on a real machine

df -h -x tmpfs -x devtmpfs -x overlay
explain

Not run in the sandbox: on a container this lists the build host's mounts; run it on your own machine. No output is shown because none was captured.

-x TYPE excludes a filesystem type and can be repeated; -t TYPE does the opposite. This leaves the real disks: root, /home, /boot and any data volumes.

Common pitfalls

  • df and du disagree when a deleted file is still open by a process: the space is in use but no name points to it. lsof +L1 finds such files; restarting the process frees the space.

  • A full filesystem with Avail 0 but Use% below 100% is usually the root reservation at work: only root can write the last few percent.

  • On copy-on-write filesystems such as Btrfs and ZFS, df numbers can be approximate because snapshots and compression change what "used" means; their own tools give the authoritative figures.

GNU vs BSD and macOS

The examples above ran the GNU/Linux version. These are the differences that matter on macOS and the BSDs (written from their documentation, not run here).

  • --output, -x and --total are GNU options. On macOS, df -h already includes inode columns, and filtering by type uses -t with a comma list where a no prefix excludes (-t noautofs).

Options worth knowing

A selection, described in our own words. For the full list, see df(1) or df --help.

OptionWhat it does
-h, --human-readablePrint sizes like 4.0K, 12M, 3.1G.
-H, --siLike -h, but in powers of 1000.
-T, --print-typeShow each filesystem's type.
-i, --inodesReport inode usage instead of blocks.
-t, --type TYPEShow only filesystems of TYPE.
-x, --exclude-type TYPELeave out filesystems of TYPE.
-l, --localShow only local filesystems.
-a, --allInclude pseudo, duplicate and inaccessible filesystems.
-kSizes in 1 KiB blocks.
-P, --portabilityUse the POSIX output format.
-B, --block-size SIZEScale sizes by SIZE, e.g. -BG.
--output[=FIELDS]Print only the listed columns, e.g. source,size,pcent,target.
--totalAdd a grand total line.

Related