How to Check Disk Space on Linux: Simple Commands Explained
To check disk space on Linux, use the
df command to see available and used space on mounted filesystems. For detailed folder sizes, use du to summarize disk usage of directories.Syntax
The df command shows disk space usage of mounted filesystems. Common options include:
-h: human-readable sizes (e.g., MB, GB)-T: show filesystem type
The du command shows disk usage of files and directories. Common options:
-h: human-readable sizes-s: summarize total sizepath: specify directory or file to check
bash
df -h du -sh /path/to/directory
Example
This example shows how to check disk space on all mounted filesystems with human-readable sizes using df -h. It also shows how to check the total size of the /var directory using du -sh /var.
bash
df -h
du -sh /varOutput
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 50G 20G 28G 42% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
12G /var
Common Pitfalls
Some common mistakes when checking disk space:
- Not using
-hoption, which makes output hard to read because sizes are in blocks. - Using
duwithout-son large directories, which prints size of every subdirectory and floods the screen. - Confusing disk space with inode usage;
dfshows both but you must specify-ito see inode info.
bash
df
du /var
df -iQuick Reference
| Command | Description |
|---|---|
| df -h | Show disk space usage in human-readable format |
| df -T | Show filesystem type along with disk usage |
| du -sh /path | Show total size of a directory in human-readable form |
| df -i | Show inode usage on filesystems |
Key Takeaways
Use
df -h to quickly see disk space on all mounted filesystems in readable units.Use
du -sh /path to find total disk usage of a specific directory.Always add
-h for human-readable sizes to avoid confusing block counts.Avoid running
du without -s on large directories to prevent overwhelming output.Use
df -i to check inode usage if disk space seems sufficient but issues persist.