0
0
Linux-cliComparisonBeginner · 3 min read

Df vs Du in Linux: Key Differences and Usage Guide

The 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.

Featuredfdu
PurposeShows disk space usage of entire filesystemsShows disk space usage of files and directories
ScopeFilesystem levelFile and directory level
Default Output UnitBlocks or human-readable sizesBlocks or human-readable sizes
Typical Use CaseCheck free space on mounted disksCheck size of specific folders or files
Includes File SizesNo, shows filesystem usageYes, sums file sizes recursively
Command Exampledf -hdu -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

bash
df -h
Output
Filesystem Size Used Avail Use% Mounted on /dev/sda1 50G 20G 28G 42% / tmpfs 1.9G 0 1.9G 0% /dev/shm
↔️

du Command Equivalent

bash
du -sh /var/log
Output
120M /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

Use df to check overall disk space and free space on filesystems.
Use du to find disk usage of specific files or directories.
df reports filesystem-level usage; du reports file-level usage.
Both commands support human-readable output with the -h option.
Choose df for quick disk health checks and du for detailed space analysis.