df
Basic Usage of df - Checking Filesystem Disk Usage
The df command is used to display information about filesystem disk space usage on Linux systems. It helps administrators monitor storage usage, detect full partitions, and troubleshoot disk-related problems.
df
Example output:
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 51200000 24500000 24000000 51% /
tmpfs 2048000 0 2048000 0% /dev/shm
/dev/sdb1 104857600 60000000 44857600 58% /data
- df stands for “disk filesystem”.
- The command displays filesystem usage information.
- The default output uses 1K blocks.
- Mounted on shows where the filesystem is attached in the directory structure.
Human Readable Output
The default output is difficult to read because it uses raw kilobytes. Most administrators use the -h option for human-readable output.
df -h
Example output:
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 50G 24G 24G 51% /
tmpfs 2.0G 0 2.0G 0% /dev/shm
/dev/sdb1 100G 60G 43G 58% /data
- The -h option means “human readable”.
- Sizes are displayed as KB, MB, GB, or TB.
- This makes storage usage easier to understand quickly.
- This is the most commonly used df option.
Displaying Filesystem Types
Different filesystems provide different features and performance characteristics. To display filesystem types:
df -T
Example output:
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/sda2 ext4 51200000 24500000 24000000 51% /
tmpfs tmpfs 2048000 0 2048000 0% /dev/shm
/dev/sdb1 xfs 104857600 60000000 44857600 58% /data
- The -T option displays the filesystem type.
- ext4 is one of the most common Linux filesystems.
- xfs is a high-performance filesystem commonly used on servers.
- tmpfs is a RAM-based temporary filesystem.
To combine filesystem types with human-readable output:
df -Th
Checking a Specific Filesystem
Sometimes you only want to inspect one filesystem or partition.
df -h /
Example output:
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 50G 24G 24G 51% /
Other useful examples:
df -h /home
df -h /var
df -h /backup
- This checks only the specified path.
- Useful for monitoring backup storage or database partitions.
- Helps isolate storage issues on specific mount points.
Displaying Inode Usage
Linux filesystems use structures called inodes to store file metadata.
df -i
Example output:
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda2 3276800 450000 2826800 14% /
- Each file consumes one inode.
- A filesystem can run out of inodes even if free disk space still exists.
- This often happens when millions of tiny files are created.
- If inode usage reaches 100%, no more files can be created.
Excluding Filesystem Types
Linux systems often contain virtual filesystems that are not useful during storage analysis.
To exclude them:
df -h -x tmpfs -x devtmpfs
- The -x option excludes filesystem types.
- tmpfs and devtmpfs are virtual filesystems.
- This creates cleaner output focused only on real storage devices.
- Commonly used in monitoring scripts.
Showing Only Specific Filesystem Types
To display only selected filesystem types:
df -t ext4
Other examples:
df -t xfs
df -t nfs
- The -t option includes only selected filesystem types.
- Useful for network filesystem monitoring.
- Helpful during filesystem migration projects.
POSIX-Compatible Output
Administrators often need consistent formatting for scripts.
df -P
- The -P option enables POSIX-compatible output.
- Prevents line wrapping on long filesystem names.
- Makes parsing output easier in shell scripts.
Example usage:
df -P / | awk 'NR==2 {print $5}'
Possible output:
51%
Displaying Total Disk Usage
To display combined totals across all mounted filesystems:
df -h --total
Example output:
total 150G 84G 67G 56% -
- The –total option calculates combined storage usage.
- Useful for capacity planning and reporting.
- Helpful for server monitoring dashboards.
Finding Nearly Full Filesystems
Administrators frequently search for filesystems nearing capacity.
df -h | grep '9[0-9]%'
Example output:
/dev/sda2 50G 49G 1G 98% /
- This filters filesystems using 90% or more storage.
- Useful for automated monitoring alerts.
- Helps identify critical storage situations quickly.
Combining Multiple Options
Linux commands often allow multiple options to be combined together.
Example:
df -hT
This combines:
- -h for human-readable output
- -T for filesystem types
Another example:
df -h --total -x tmpfs
- Displays human-readable sizes
- Shows combined totals
- Excludes virtual filesystems
df vs du
Many beginners confuse df and du.
df -h
- df displays filesystem usage and available space.
du -sh /var/log
- du displays the size of directories and files.
Think of it this way:
- df answers: “How full is the filesystem?”
- du answers: “Which directories consume space?”
Practical Monitoring Script
The following script warns when partitions exceed 90% usage:
#!/bin/bash
THRESHOLD=90
df -hP | awk 'NR>1 {print $1,$5}' | while read output;
do
usage=$(echo $output | awk '{print $2}' | cut -d'%' -f1)
partition=$(echo $output | awk '{print $1}')
if [ $usage -ge $THRESHOLD ]; then
echo "WARNING: $partition is ${usage}% full"
fi
done
- Checks all mounted filesystems
- Extracts usage percentages
- Compares them against a threshold
- Displays warnings for nearly full partitions
Summary
In this guide, you’ve learned how to use the df command to monitor filesystem disk usage effectively. You’ve practiced:
Basic filesystem inspection
Human-readable output
Displaying filesystem types
Monitoring inode usage
Excluding virtual filesystems
Filtering filesystem types
Monitoring nearly full partitions
Using df in shell scripts
These skills are essential for:
- Linux administration
- Server monitoring
- Troubleshooting storage issues
- Capacity planning
- Infrastructure maintenance
Additional df parameters not covered in this guide include:
-a: Include pseudo and duplicate filesystems
-B SIZE: Display sizes in a specific block size
--si: Use powers of 1000 instead of 1024
--sync: Sync filesystems before getting usage info
--output: Customize displayed columns
--help: Display help information
--version: Display version information