df
Show disk space usage
TLDR
Display all filesystems and their disk usage using 512-byte units
Display the filesystem and its disk usage containing the given file or directory
Use 1024-byte units when writing space figures
Display information in a portable way
SYNOPSIS
df [OPTION]... [FILE]...
The df command reports the amount of disk space used and available on file systems. If FILE is specified, df displays information about the file system on which FILE resides.
PARAMETERS
-a, --all
Includes pseudo, duplicate, and inaccessible file systems in the output.
-B, --block-size=SIZE
Scales sizes by SIZE before printing them. For example, '-B M' for megabytes.
-h, --human-readable
Prints sizes in human readable format (e.g., 1K, 234M, 2G).
-H, --si
Similar to --human-readable, but uses powers of 1000 (SI units) instead of 1024.
-i, --inodes
Displays inode usage information instead of disk block usage.
-k
Same as --block-size=1K. Displays sizes in 1-kilobyte blocks.
-l, --local
Limits the listing to local file systems only.
-P, --portability
Uses the POSIX output format, ensuring consistent field order and block sizes.
-t, --type=TYPE
Restricts the listing to file systems of the specified TYPE (e.g., 'ext4', 'nfs').
-x, --exclude-type=TYPE
Excludes file systems of the specified TYPE from the output.
--total
Produces a grand total of all shown file systems at the end of the output.
DESCRIPTION
df (disk free) is a standard Unix/Linux command-line utility used to display information about total disk space, used space, available space, and percentage usage for mounted file systems. It provides a quick overview of how much storage is consumed on various partitions, network shares, and other storage devices accessible by your system. The command typically outputs data in 1K blocks by default, but options exist to present this information in a more human-readable format, such as megabytes or gigabytes. This utility is crucial for system administrators and users alike to monitor disk capacity, identify potential storage bottlenecks, and manage resources effectively. It helps in understanding if a particular partition is nearing full capacity, which could impact system performance or prevent new data from being written. df retrieves its information from the kernel's file system metadata, making it a reliable source for current disk utilization statistics without needing to scan individual files or directories. Its output usually includes columns like Filesystem, 1K-blocks, Used, Available, Use%, and Mounted on.
CAVEATS
One important caveat is that df reports available space from the perspective of a non-root user. Most Linux file systems reserve a small percentage (e.g., 5%) of disk blocks for the root user to prevent the file system from becoming completely full, which could lead to system instability. This reserved space is not typically counted in the 'Available' column for regular users.
Additionally, df reports the space currently allocated on the file system. If a file is deleted but still held open by a running process, the space occupied by that file might not be immediately freed and thus not reflected in df's output until the process releases the file handle. Network file systems like NFS can also sometimes report stale data or cause df to hang if the remote server is unresponsive.
UNDERSTANDING 'AVAILABLE' VS. 'TOTAL - USED'
A common source of confusion is why the 'Available' space reported by df is often less than the 'Total' space minus the 'Used' space. This discrepancy is primarily due to reserved blocks on file systems (especially ext family file systems). By default, a small percentage of disk blocks (typically 5% for ext4) is reserved for the root user. This reservation serves critical purposes: it ensures the system can continue to operate and log errors even if a regular user fills the disk, and it helps prevent file system fragmentation. df's 'Available' column reflects the space usable by non-root users, hence excluding these reserved blocks. The root user, however, can utilize this reserved space when needed.
DF VS. DU: A KEY DISTINCTION
While both df and du (disk usage) relate to disk space, they operate on different principles and provide different insights.
df (disk free) reports disk space usage from the perspective of the file system metadata. It queries the file system directly about its total capacity, used blocks, and available blocks. This means it reflects the space actually allocated by the file system, regardless of whether individual files contributing to that space are still accessible or have been deleted but remain open by a process.
du (disk usage), on the other hand, works by recursively scanning a directory tree and summing the sizes of individual files within it. It reflects the space consumed by files and directories that are currently visible and accessible.
The key implication is that df and du reports for the same partition can sometimes differ. This often happens if files have been deleted but are still held open by processes (where df won't show the space freed), or due to hard links (where du counts space for each link, while df counts it once).
HISTORY
The df command has been a fundamental utility since the early days of Unix, appearing in Research Unix, BSD, and System V releases. Its primary function, to report disk space, has remained consistent throughout its evolution. On Linux, df is part of the GNU coreutils package, which provides a comprehensive set of basic system utilities. The development of the GNU version has focused on adding features like human-readable output (the -h option), support for various block sizes, and filtering options (-t, -x) to enhance its flexibility and user-friendliness over time, making it an indispensable tool for system administration.