Linux Command Reference ยท Disks and Filesystems
Linux df command
Reference for the Linux df command: show size, used and available space per filesystem, use -h, -i and -T, pick columns with --output, and avoid common surprises.
df ("disk free") reports how much space each mounted filesystem has, how much is used and how much is left. It asks the filesystem itself, so it is fast and shows the real picture even when files are spread over many directories. To find out which files use the space, use du.
Give it a file or directory and df reports on the filesystem that contains it, which answers the practical question "is there room to write here?".
df [OPTION]... [FILE]...
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
df [-h | -H | -k | -m | -B SIZE] [-a] [-i] [-l] [-P] [-T] [-t TYPE] [-x TYPE] [--total] [--output[=FIELDS]] [FILE]...
| Option | Description |
|---|---|
-h |
Human-readable sizes with powers of 1024 (1.5G). |
-H, --si |
Same, with powers of 1000. |
-k, -m |
Force 1 KiB or 1 MiB units. -B SIZE sets any block size, such as -BG or -B1. |
-i |
Report inodes (file count capacity) instead of blocks. |
-T |
Add a column with the filesystem type. |
-t TYPE |
Only list filesystems of this type. -x TYPE excludes a type. Both are repeatable. |
-l |
Only local filesystems, skip network mounts. |
-a |
Include pseudo, duplicate and inaccessible filesystems that are hidden by default. |
-P |
POSIX output: one line per filesystem, 1024-byte blocks by default, never wraps long names. |
--total |
Add a grand total line. |
--output[=FIELDS] |
Choose columns: source, fstype, itotal, iused, iavail, ipcent, size, used, avail, pcent, file, target. |
FILE |
Report on the filesystem holding this file or directory. |
Returns: 0 if all operands could be read; 1 if any failed (for example a path that does not exist).
Usage notes
Used + Availis less thanSize. Ext filesystems reserve about 5 % of blocks for root by default, so ordinary users can run out of space whileSize - Usedstill looks positive. TheUse%column is calculated against what non-root users may use.- 100 % use with free space left is possible in another way: running out of inodes. A directory with millions of tiny files can make
df -hlook fine anddf -ishow100%. Writes then fail with "No space left on device". - Deleted but open files keep their space until the last process closes them.
dfshows the disk as full whileducannot find the files.lsof +L1lists them (seelsof). - Different numbers than
du.dfcounts allocated blocks of the whole filesystem including metadata and journals;duadds up the files it can see. Small differences are normal. - Containers and overlays. On overlay filesystems the numbers describe the host disk that backs the layers, not a per-container quota.
- tmpfs and other memory-backed mounts (
/dev/shm,/run, sometimes/tmp) show their configured size; they only use memory for the data actually stored. - Slow on stale NFS mounts.
dfstats every filesystem, and a hung network mount can block it. Usedf -lor name the path you care about. - Scripting. Use
--output=withtail -1instead of cutting columns by position; names with spaces breakawk '{print $5}'. - Snapshots and compression (Btrfs, ZFS) make
dfapproximate; use the filesystem's own tools for exact accounting.
Related
du,lsblk,mount,findmnt,stat- Lessons: Disk Usage, Disks and Logs