0
0
Linux-cliHow-ToBeginner · 3 min read

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 size
  • path: 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 /var
Output
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 -h option, which makes output hard to read because sizes are in blocks.
  • Using du without -s on large directories, which prints size of every subdirectory and floods the screen.
  • Confusing disk space with inode usage; df shows both but you must specify -i to see inode info.
bash
df

du /var

df -i
📊

Quick Reference

CommandDescription
df -hShow disk space usage in human-readable format
df -TShow filesystem type along with disk usage
du -sh /pathShow total size of a directory in human-readable form
df -iShow 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.