Disks and filesystems
df
Report how much space is used and free on mounted filesystems.
df [OPTION...] [FILE...]
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 .
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 .
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
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 .
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
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
ok: 0% used
Which filesystem holds a file
df -h data/users.csv
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
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
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
dfanddudisagree when a deleted file is still open by a process: the space is in use but no name points to it.lsof+L1finds such files; restarting the process frees the space.A full filesystem with
Avail0 butUse%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,
dfnumbers 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,-xand--totalare GNU options. On macOS,df -halready includes inode columns, and filtering by type uses-twith a comma list where anoprefix excludes (-t noautofs).
Options worth knowing
A selection, described in our own words. For the full list, see df(1) or df --help.
| Option | What it does |
|---|---|
-h, --human-readable | Print sizes like 4.0K, 12M, 3.1G. |
-H, --si | Like -h, but in powers of 1000. |
-T, --print-type | Show each filesystem's type. |
-i, --inodes | Report inode usage instead of blocks. |
-t, --type TYPE | Show only filesystems of TYPE. |
-x, --exclude-type TYPE | Leave out filesystems of TYPE. |
-l, --local | Show only local filesystems. |
-a, --all | Include pseudo, duplicate and inaccessible filesystems. |
-k | Sizes in 1 KiB blocks. |
-P, --portability | Use the POSIX output format. |
-B, --block-size SIZE | Scale sizes by SIZE, e.g. -BG. |
--output[=FIELDS] | Print only the listed columns, e.g. source,size,pcent,target. |
--total | Add a grand total line. |
Related
duShow how much disk space files and directories use, totalled per directory.findmntShow mounted filesystems as a tree, or look up which filesystem a path is on and how it is mounted.lsblkList block devices (disks, partitions, LVM volumes, loop devices) as a tree, with sizes and mount points.mountAttach a filesystem (a disk partition, image, network share or tmpfs) to a directory, or list what is mounted.statShow a file's metadata (size, permissions, owner, inode, timestamps), or print chosen fields in your own format.