Chapter 29: Bash Disk Space (df)
What does df actually do? (super simple first)
df = disk free It shows you how much disk space is used and how much is still free on your mounted filesystems (hard drives, SSDs, USBs, network drives, etc.).
In simple words:
- Tells you which partition/drive is almost full
- Shows total size, used space, available space, % used
- Very fast – doesn’t scan files, just asks the filesystem
Without df, you might suddenly get “No space left on device” error and not know which folder/drive is the culprit.
1. Basic usage (try right now!)
Just type:
|
0 1 2 3 4 5 6 |
df |
You will see something like this (example from a typical laptop):
|
0 1 2 3 4 5 6 7 8 9 10 11 12 |
Filesystem 1K-blocks Used Available Use% Mounted on tmpfs 3200000 2048 3197952 1% /run /dev/sda5 234567890 145678901 76543210 66% / tmpfs 8000000 0 8000000 0% /dev/shm tmpfs 5120 12 5108 1% /run/lock /dev/sda1 10485760 345678 10140082 4% /boot/efi /dev/sdb1 976762584 456789012 519973572 47% /home |
2. Make it human-readable (most important flag – always use this!)
|
0 1 2 3 4 5 6 7 8 |
df -h # or df --human-readable |
Now it shows sizes in GB, MB, TB instead of 1K-blocks:
|
0 1 2 3 4 5 6 7 8 9 10 11 |
Filesystem Size Used Avail Use% Mounted on tmpfs 3.1G 2.0M 3.1G 1% /run /dev/sda5 224G 140G 74G 66% / tmpfs 7.6G 0 7.6G 0% /dev/shm /dev/sda1 10G 338M 9.7G 4% /boot/efi /dev/sdb1 931G 436G 496G 47% /home |
Much easier to understand!
3. Very common options (you’ll use these 90% of time)
| Option | What it does | Example command | Why useful? |
|---|---|---|---|
| -h | Human-readable (GB, MB, TB) | df -h | Always use this! |
| -T | Show filesystem type (ext4, ntfs, vfat…) | df -hT | Know if ext4, btrfs, etc. |
| –total | Add grand total line at bottom | df -h –total | Quick total disk space |
| -i | Show inode usage (not just bytes) | df -hi | When “no space” but df shows free space |
| –output=… | Choose which columns to show | df -h –output=source,size,used,avail,pcent,target | Clean reports |
| -t / -x | Include/exclude filesystem types | df -h -t ext4 -t btrfs | Only real disks |
4. Real examples you should try right now
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# Most common daily check df -h # Only root filesystem (very useful) df -h / # Only your home folder drive df -h /home # All disks + total + filesystem type df -hT --total # See which filesystem is fullest df -h | sort -k 5 -nr | head -n 6 # Only real disks (exclude tmpfs, devtmpfs, etc.) df -h -x tmpfs -x devtmpfs # Check inode usage (very important when many small files) df -hi / # Pretty formatted for scripts/reports df -h --output=source,fstype,size,used,avail,use%,pcent,target | column -t |
5. Understanding the columns (very important!)
| Column | Meaning | Example value | When to worry |
|---|---|---|---|
| Filesystem | Device name or mount point | /dev/sda5 | – |
| Size | Total capacity | 224G | – |
| Used | Space already used | 140G | High = danger |
| Avail | Space still free | 74G | <10–15% → alert |
| Use% | Percentage used | 66% | >90% = critical |
| Mounted on | Where it’s attached in directory tree | / | – |
Rule of thumb (from sysadmins):
- < 80% used → comfortable
- 80–90% → start cleaning / watching
-
90% → urgent – delete logs, old downloads, temp files
- 100% → system may become unstable (especially /)
6. Real-life examples (Hyderabad style)
- Laptop saying “disk full” when downloading movie?
Bash01234567df -h /home# If /home is 95% → check big files: du -sh ~/Downloads/* | sort -hr | head
- Server slow after many Docker containers?
Bash01234567df -h /var/lib/docker# If full → docker system prune -a
- Check before big backup
Bash0123456df -h /mnt/backup-drive
- See total disk space across all drives
Bash0123456df -h --total | tail -1
7. Quick cheat-sheet table
| Goal | Command example | Notes |
|---|---|---|
| Quick look (human readable) | df -h | Everyday use |
| Only root partition | df -h / | Most critical |
| Show filesystem types | df -hT | ext4 vs ntfs |
| Add total line | df -h –total | Grand total |
| Sort by % used descending | df -h |
sort -k 5 -nr |
| Only real disks | df -h -x tmpfs -x devtmpfs | Ignore RAM disks |
| Inode usage (many small files) | df -hi | “No space” but space free? |
| Clean columns only | df -h –output=source,size,used,avail,use%,target | Reports |
8. Pro tips from daily use
- Always use -h – numbers without it are confusing (1K-blocks)
- When “No space left” but df shows free space → check inodes with -i
- df only shows mounted filesystems – unmounted drives won’t appear
- For more detail (which folder eating space) → use du, not df
Bash0123456sudo du -sh /* | sort -hr | head -10
Now open your terminal and try these 3 right now:
|
0 1 2 3 4 5 6 7 8 |
df -h df -h / df -h --total | tail -1 |
Tell me:
- How much % is your root (/) using right now?
- Or ask: “What to do if / is 95% full?” or “df vs du – difference?” or “How to check external USB drive?”
We’ll solve it together! 😄
