Df vs Du in Linux: Key Differences and Usage Guide
df command in Linux shows disk space usage of entire filesystems, while du reports disk usage of files and directories. Use df to check free space on disks and du to find how much space specific folders or files consume.Quick Comparison
Here is a quick side-by-side comparison of df and du commands in Linux.
| Feature | df | du |
|---|---|---|
| Purpose | Shows disk space usage of entire filesystems | Shows disk space usage of files and directories |
| Scope | Filesystem level | File and directory level |
| Default Output Unit | Blocks or human-readable sizes | Blocks or human-readable sizes |
| Typical Use Case | Check free space on mounted disks | Check size of specific folders or files |
| Includes File Sizes | No, shows filesystem usage | Yes, sums file sizes recursively |
| Command Example | df -h | du -sh /path/to/dir |
Key Differences
The df command reports the amount of disk space used and available on entire filesystems. It reads filesystem metadata to show total size, used space, and free space for each mounted filesystem. This makes it useful for quickly checking overall disk health and capacity.
In contrast, du calculates disk usage by walking through directories and summing the sizes of files and subdirectories. It shows how much space specific files or folders consume, which helps identify large directories or files eating up space.
While df focuses on the storage device level, du focuses on the content level inside directories. Both commands support human-readable output with the -h option for easier understanding.
df Command Example
df -h
du Command Equivalent
du -sh /var/log
When to Use Which
Choose df when you want to see how much free space is left on your disks or partitions. It gives a quick overview of all mounted filesystems.
Choose du when you want to find out which files or directories are using the most space. It helps you clean up large folders or files.
In summary, use df for disk-level space info and du for file-level space details.
Key Takeaways
df to check overall disk space and free space on filesystems.du to find disk usage of specific files or directories.df reports filesystem-level usage; du reports file-level usage.-h option.df for quick disk health checks and du for detailed space analysis.