What it is
df reports file system disk space usage, showing how much space is used and available on mounted file systems.
Installation
df is a standard Unix utility and is pre-installed on most Linux and macOS systems.
Core Concepts
- File System: A hierarchical structure for organizing and storing files on a storage device.
dfreports usage for each mounted file system. - Mount Point: The directory where a file system is attached to the main file system hierarchy.
- Inodes: Data structures that store information about files and directories (permissions, ownership, timestamps, etc.). Running out of inodes can prevent new files from being created, even if disk space is available.
Commands / Usage
Basic Usage
dfReport disk space usage for all mounted file systems.df .Report disk space usage for the file system containing the current directory.df /homeReport disk space usage for the file system mounted at/home.
Human-Readable Output
df -hReport disk space usage in human-readable format (e.g., 1K, 234M, 2G).df -HReport disk space usage in human-readable format using powers of 1000 (e.g., 1KB, 234MB, 2GB).
Specific File System Types
df -t ext4Report disk space usage only for file systems of typeext4.df -TReport the file system type for each mounted file system.
Excluding File System Types
df -x tmpfsReport disk space usage for all file systems except those of typetmpfs.
Inode Usage
df -iReport inode usage for all mounted file systems.df -hiReport inode usage in human-readable format.
Output Formatting
df --output=source,avail,targetSpecify the columns to display. Common options includesource,fstype,itotal,iused,iavail,ipcent,size,used,avail,pcent,target.df --totalProduce a grand total line at the end of the output.
Common Patterns
df -h | grep '/dev/sda'Show disk usage for partitions on/dev/sdain human-readable format.df -h /var/logCheck disk space for the file system where/var/logresides.df -i | awk 'NR>1 && $5 > 80'Find file systems with more than 80% inode usage (excluding the header line).df -h -t nfsDisplay usage for all mounted NFS file systems in human-readable format.df -h -x tmpfs -x devtmpfsShow disk usage for real storage, excluding temporary file systems.
Gotchas
- Mounted Devices vs. Physical Disks:
dfreports on mounted file systems, not raw physical disks. A single physical disk can host multiple file systems (e.g., partitions), anddfwill show them separately if mounted. - Deleted Files and Open Handles: If a file is deleted but still held open by a running process, the space it occupied will not be freed until the process closes the file handle.
dfwill reflect the space as used, butdu(disk usage) might not show the deleted file. - Root File System and Overflows: If the root file system (
/) fills up, it can cause system instability, even if other file systems have space. This is because many system processes write temporary files or logs to/var/logor/tmp, which are often on the root file system. tmpfsand RAM: File systems of typetmpfs(often mounted at/dev/shm,/run,/tmp) reside in RAM and swap space. Their reported "disk space" is volatile and not persistent storage.- Permissions: You need appropriate permissions to see usage for all mounted file systems.