df Disk Free

df cheatsheet — check disk space on Linux filesystems. df -h for human-readable, df -T for filesystem type, df /path for specific mount. Every df flag covered.

3 min read

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. df reports 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

  • df Report disk space usage for all mounted file systems.
  • df . Report disk space usage for the file system containing the current directory.
  • df /home Report disk space usage for the file system mounted at /home.

Human-Readable Output

  • df -h Report disk space usage in human-readable format (e.g., 1K, 234M, 2G).
  • df -H Report disk space usage in human-readable format using powers of 1000 (e.g., 1KB, 234MB, 2GB).

Specific File System Types

  • df -t ext4 Report disk space usage only for file systems of type ext4.
  • df -T Report the file system type for each mounted file system.

Excluding File System Types

  • df -x tmpfs Report disk space usage for all file systems except those of type tmpfs.

Inode Usage

  • df -i Report inode usage for all mounted file systems.
  • df -hi Report inode usage in human-readable format.

Output Formatting

  • df --output=source,avail,target Specify the columns to display. Common options include source, fstype, itotal, iused, iavail, ipcent, size, used, avail, pcent, target.
  • df --total Produce a grand total line at the end of the output.

Common Patterns

  • df -h | grep '/dev/sda' Show disk usage for partitions on /dev/sda in human-readable format.
  • df -h /var/log Check disk space for the file system where /var/log resides.
  • df -i | awk 'NR>1 && $5 > 80' Find file systems with more than 80% inode usage (excluding the header line).
  • df -h -t nfs Display usage for all mounted NFS file systems in human-readable format.
  • df -h -x tmpfs -x devtmpfs Show disk usage for real storage, excluding temporary file systems.

Gotchas

  • Mounted Devices vs. Physical Disks: df reports on mounted file systems, not raw physical disks. A single physical disk can host multiple file systems (e.g., partitions), and df will 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. df will reflect the space as used, but du (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/log or /tmp, which are often on the root file system.
  • tmpfs and RAM: File systems of type tmpfs (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.