To check disk space in Linux, use df -h to see how much space is used and free on each mounted filesystem, and du -sh directory/ to see how much space a specific directory uses. The -h flag makes sizes human-readable (showing GB, MB instead of bytes). For example, df -h / shows the disk usage of your root filesystem, and du -sh ~ shows your home directory’s total size. Use du -sh /* 2>/dev/null | sort -rh | head -20 to find the largest directories on your system.
Running Out of Disk Space Before You See It Coming
Disk space problems on Linux have a characteristic pattern: everything works fine until suddenly it does not. An application crashes. A database refuses to write. A log file stops growing mid-entry. System updates fail. You try to save a file and receive “No space left on device.” The culprit is almost always a disk that filled up silently — log files that accumulated for months, a download folder that was never cleaned, a database that kept growing, cached packages from hundreds of updates.
The solution is regular disk space monitoring and, when problems arise, knowing exactly how to find what is consuming space. Linux provides excellent tools for this: df for a quick overview of filesystem usage, du for drilling down into directory trees to find space consumers, lsblk for understanding the storage layout, and ncdu for interactive, visual disk usage exploration.
Understanding how to use these tools effectively — and building the habit of checking disk space before problems occur — is practical system hygiene for any Linux user or administrator. This article covers every tool you need, with practical workflows for finding and addressing disk space problems.
df: Disk Filesystem Usage Overview
df (disk free) reports how much space is used and available on each mounted filesystem. It gives you the bird’s-eye view of your storage situation.
Basic df Usage
$ df -h
Filesystem Size Used Avail Use% Mounted on
tmpfs 3.2G 2.1M 3.2G 1% /run
/dev/nvme0n1p2 469G 231G 214G 52% /
tmpfs 16G 267M 16G 2% /dev/shm
tmpfs 5.0M 8.0K 5.0M 1% /run/lock
/dev/nvme0n1p1 1.1G 11M 1.1G 1% /boot/efi
/dev/sda1 916G 87G 783G 10% /mnt/storage
tmpfs 3.2G 1.6M 3.2G 1% /run/user/1000
The -h flag (human-readable) converts bytes into KB, MB, GB — essential for readability.
Reading df Output
Each row represents one mounted filesystem:
- Filesystem — the device or virtual filesystem (
/dev/nvme0n1p2,tmpfs) - Size — total capacity of this filesystem
- Used — how much is currently occupied
- Avail — how much is available to write (note: this is less than Size – Used because some space is reserved for the root user)
- Use% — percentage used — the most immediately useful column
- Mounted on — where in the filesystem tree this is accessible
The reserved space: ext4 filesystems reserve 5% of space for root by default. On a 500 GB partition, that is 25 GB reserved. Regular users cannot use this space, but root can. This is why Used + Avail does not always equal Size. Change the reserved percentage with tune2fs -m 1 /dev/device (reduces reservation to 1%).
Filtering df Output
Show only real filesystems (exclude tmpfs and other virtual filesystems):
$ df -h -x tmpfs -x devtmpfs
Filesystem Size Used Avail Use% Mounted on
/dev/nvme0n1p2 469G 231G 214G 52% /
/dev/nvme0n1p1 1.1G 11M 1.1G 1% /boot/efi
/dev/sda1 916G 87G 783G 10% /mnt/storage
Show only a specific filesystem:
$ df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/nvme0n1p2 469G 231G 214G 52% /
$ df -h /mnt/storage
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 916G 87G 783G 10% /mnt/storage
Show filesystem type:
$ df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/nvme0n1p2 ext4 469G 231G 214G 52% /
/dev/sda1 ext4 916G 87G 783G 10% /mnt/storage
Inode Usage: The Other Disk Limit
Filesystems have two scarce resources: disk blocks (actual storage space) and inodes (metadata records for each file). You can run out of inodes while still having plenty of disk space — at which point no new files can be created even though df -h shows available space.
Check inode usage:
$ df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/nvme0n1p2 30539776 1456234 29083542 5% /
/dev/sda1 61054976 234567 60820409 1% /mnt/storage
High inode usage (>90%) is typically caused by millions of tiny files — mail spools, package caches, or applications that create one file per item. Solutions: clean up small files, or reformat with a larger inode count.
du: Directory and File Space Usage
While df shows overall filesystem usage, du (disk usage) shows how much space a specific directory and its contents consume. This is the tool for finding what is taking up space within a filesystem.
Basic du Usage
Total size of a directory:
$ du -sh ~/Documents
4.7G /home/sarah/Documents
$ du -sh /var/log
1.2G /var/log
The -s flag summarizes (shows only the total, not each subdirectory), and -h makes sizes human-readable.
Size of multiple directories:
$ du -sh ~/Documents ~/Downloads ~/Videos
4.7G /home/sarah/Documents
23G /home/sarah/Downloads
87G /home/sarah/Videos
Size breakdown of subdirectories:
$ du -h --max-depth=1 ~
4.7G /home/sarah/Documents
23G /home/sarah/Downloads
87G /home/sarah/Videos
1.2G /home/sarah/Music
124K /home/sarah/.config
456K /home/sarah/.local
116G /home/sarah
--max-depth=1 shows sizes for each immediate subdirectory without recursing further.
Finding the Largest Directories
The most practically useful du command — find the biggest space consumers anywhere on the system:
$ sudo du -sh /* 2>/dev/null | sort -rh | head -20
87G /home
23G /var
14G /usr
3.2G /opt
1.8G /snap
1.2G /boot
...
2>/dev/null suppresses permission denied errors. sort -rh sorts by human-readable size in reverse (largest first). head -20 shows only the top 20.
Then drill into the largest directories:
$ sudo du -sh /home/* 2>/dev/null | sort -rh | head -10
116G /home/sarah
12G /home/bob
4G /home/alice
$ du -sh ~/Videos ~/Downloads | sort -rh
87G /home/sarah/Videos
23G /home/sarah/Downloads
Continue drilling down until you find the specific directories consuming the most space.
Finding Large Files Directly
Sometimes the space consumer is a single large file:
$ find ~ -type f -size +1G -exec ls -lh {} \; 2>/dev/null
-rw-r--r-- 1 sarah sarah 45G Feb 10 08:00 /home/sarah/Videos/vacation.mkv
-rw-r--r-- 1 sarah sarah 12G Feb 05 14:30 /home/sarah/Downloads/iso_backup.iso
$ find /var -type f -size +500M 2>/dev/null
/var/lib/docker/overlay2/abc123/merged/large_layer.tar
du with Sorting: One-Liner for Large Subdirectories
A very useful combination — show subdirectory sizes sorted largest first:
$ du -h --max-depth=1 /var | sort -rh
1.2G /var
456M /var/lib
312M /var/cache
234M /var/log
89M /var/backups
For the current directory:
$ du -h --max-depth=1 . | sort -rh
ncdu: Interactive Disk Usage Explorer
ncdu (NCurses Disk Usage) is a terminal-based interactive disk usage analyzer — the most user-friendly way to explore disk space usage, navigate directory trees, and identify space consumers visually.
Installing ncdu
$ sudo apt install ncdu # Ubuntu/Debian
$ sudo dnf install ncdu # Fedora
Using ncdu
$ ncdu / # Scan the entire filesystem (use sudo for complete access)
$ sudo ncdu / # Scan as root for full visibility
$ ncdu ~/ # Scan your home directory
$ ncdu /var # Scan a specific directory
While ncdu scans (which may take a minute for large directories), it shows a progress bar. When complete:
--- /home/sarah ----------------------------------------------------------
116.4 GiB [##########] /Videos
23.1 GiB [## ] /Downloads
4.7 GiB [ ] /Documents
1.2 GiB [ ] /Music
124.0 MiB [ ] /.local
89.6 MiB [ ] /.cache
Navigation:
↑/↓— move up and down the listEnter— descend into the selected directory←orqin a directory — go back upd— delete the selected file or directory (with confirmation)n— sort by names— sort by size (default)C— sort by item countg— toggle percentage/graph displaye— show/hide hidden filesi— show information about the selected itemq— quit
ncdu’s interactive navigation makes it far faster than repeated du commands for exploring an unfamiliar system’s disk usage. The visual size bars give an immediate intuitive sense of relative usage.
Scanning Remote Systems
$ ssh user@server "sudo ncdu -o- /" | ncdu -f-
This runs ncdu on a remote server and pipes the output to local ncdu for interactive exploration — useful for analyzing remote disk usage without installing ncdu there.
lsblk: Understanding Storage Layout
Before checking space on a specific partition, understanding the storage layout helps:
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
nvme0n1 259:0 0 477G 0 disk
├─nvme0n1p1 259:1 0 1.1G 0 part /boot/efi
├─nvme0n1p2 259:2 0 470.9G 0 part /
└─nvme0n1p3 259:3 0 5G 0 part [SWAP]
sda 8:0 0 931.5G 0 disk
└─sda1 8:1 0 931.5G 0 part /mnt/storage
lsblk shows physical drives, their partitions, and where each is mounted. This context is essential for understanding what df shows — knowing that / and /mnt/storage are on separate physical drives explains why they have different space availability.
Common Disk Space Consumers and How to Find Them
Log Files
$ du -sh /var/log
1.2G /var/log
$ du -h --max-depth=1 /var/log | sort -rh | head -10
1.2G /var/log
456M /var/log/journal
234M /var/log/apt
89M /var/log/syslog
45M /var/log/kern.log
# Find large log files specifically
$ find /var/log -type f -size +50M -exec ls -lh {} \;
Clean up:
# Clean old compressed logs
$ sudo find /var/log -name "*.gz" -mtime +30 -delete
# Vacuum systemd journal (keep last 2 weeks)
$ sudo journalctl --vacuum-time=2weeks
# Clean APT cache
$ sudo apt clean
Package Manager Cache
$ du -sh /var/cache/apt
876M /var/cache/apt
$ du -sh /var/cache/apt/archives
834M /var/cache/apt/archives
Clean up:
$ sudo apt clean # Remove all cached .deb files
$ sudo apt autoclean # Remove only outdated cached packages
$ sudo apt autoremove # Remove unused dependency packages
On Fedora:
$ sudo dnf clean all
$ sudo dnf autoremove
Snap Packages
Snap keeps old revisions of installed packages:
$ du -sh /var/lib/snapd/snaps
3.4G /var/lib/snapd/snaps
$ snap list --all | grep disabled
firefox 122.0 3778 latest/stable mozilla disabled
vlc 3.0.19 3645 latest/stable videolan disabled
Remove old snap revisions:
$ snap list --all | awk '/disabled/{print $1, $3}' | while read snapname revision; do
sudo snap remove "$snapname" --revision="$revision"
done
Or with the common one-liner:
$ snap list --all | grep disabled | awk '{print $1 " --revision " $3}' | xargs -n 3 sudo snap remove
Docker
Docker can accumulate substantial disk usage:
$ docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 23 8 14.2GB 9.8GB (69%)
Containers 12 3 1.2GB 780MB (65%)
Local Volumes 8 5 4.3GB 1.1GB (25%)
Build Cache 0 0 0B 0B
$ docker system prune # Remove stopped containers, unused networks, dangling images
$ docker system prune -a # Also remove unused images (more aggressive)
$ docker volume prune # Remove unused volumes
Large Files in /tmp and /var/tmp
$ du -sh /tmp /var/tmp
234M /tmp
1.2G /var/tmp
$ find /tmp /var/tmp -type f -size +100M -exec ls -lh {} \;
Trash
The desktop trash (Recycle Bin equivalent) does not free space until emptied:
$ du -sh ~/.local/share/Trash
4.5G /home/sarah/.local/share/Trash
$ trash-empty # If trash-cli is installed
# Or:
$ rm -rf ~/.local/share/Trash/*
Home Directory Clutter
$ du -sh ~/.cache
2.3G /home/sarah/.cache
# Cache can generally be safely deleted
$ rm -rf ~/.cache/*
# Find large hidden directories
$ du -sh ~/.[^.]* 2>/dev/null | sort -rh | head -10
2.3G /home/sarah/.cache
1.1G /home/sarah/.local
456M /home/sarah/.mozilla
234M /home/sarah/.config
Monitoring Disk Space Automatically
Setting Up Regular Disk Space Alerts
A cron job that sends an alert when disk usage exceeds a threshold:
$ crontab -e
Add:
0 8 * * * /home/sarah/scripts/check_disk.sh
Script:
#!/bin/bash
THRESHOLD=85
HOSTNAME=$(hostname)
df -h | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{print $5 " " $6}' | while read output; do
usage=$(echo $output | awk '{print $1}' | tr -d '%')
partition=$(echo $output | awk '{print $2}')
if [ "$usage" -ge "$THRESHOLD" ]; then
echo "ALERT: Disk $partition on $HOSTNAME is ${usage}% full" | \
mail -s "Disk Space Alert: $partition at ${usage}%" admin@example.com
fi
done
Using watch for Continuous Monitoring
$ watch -n 60 df -h # Refresh disk space display every 60 seconds
Quick Reference: Disk Space Commands
| Task | Command |
|---|---|
| Show all filesystem usage | df -h |
| Show only real filesystems | df -h -x tmpfs -x devtmpfs |
| Show filesystem type | df -hT |
| Check inode usage | df -i |
| Show directory total size | du -sh directory/ |
| Show subdirectory sizes | du -h --max-depth=1 directory/ |
| Find largest dirs in / | sudo du -sh /* 2>/dev/null | sort -rh | head -20 |
| Find files larger than 1GB | find / -size +1G -type f 2>/dev/null |
| Interactive disk explorer | ncdu directory/ |
| Show storage layout | lsblk |
| Clean APT cache | sudo apt clean && sudo apt autoremove |
| Clean DNF cache | sudo dnf clean all |
| Vacuum journal logs | sudo journalctl --vacuum-time=2weeks |
| Check Docker usage | docker system df |
| Clean Docker | docker system prune |
| Remove old snaps | snap list --all | grep disabled | ... |
| Check trash size | du -sh ~/.local/share/Trash |
Practical Workflow: Diagnosing a Full Disk
When df -h shows 95%+ usage on a partition, here is a systematic approach:
Step 1: Identify which filesystem is full:
$ df -h
Note which mount point is at high usage.
Step 2: Find the top directories within that filesystem:
$ sudo ncdu / # Interactive — fastest approach
# Or manually:
$ sudo du -sh /* 2>/dev/null | sort -rh | head -10
Step 3: Drill down into the largest directory:
$ sudo du -h --max-depth=1 /var | sort -rh
$ sudo du -h --max-depth=1 /var/log | sort -rh
Step 4: Address common culprits in order:
$ sudo apt clean # APT cache
$ sudo journalctl --vacuum-size=500M # Journal logs
$ sudo apt autoremove # Unused packages
$ docker system prune # Docker (if applicable)
$ find /var/log -name "*.gz" -mtime +30 -delete # Old compressed logs
Step 5: Find and review large files:
$ sudo find /var -type f -size +100M 2>/dev/null | sort -k5 -rn
Step 6: Verify improvement:
$ df -h
This systematic process typically resolves disk space problems within minutes.
Conclusion: Disk Space Visibility Prevents Crises
Disk space problems are almost always preventable. The tools exist — df for instant overview, du for directory drilling, ncdu for interactive exploration — and they take seconds to run. The difference between a disk that fills unexpectedly and one that stays manageable is the habit of checking regularly and addressing accumulation before it becomes critical.
The commands to internalize: df -h as your daily sanity check, du -sh directory/ when you suspect a space consumer, and sudo ncdu / when you need to find and investigate the culprit visually. With these three tools, you have everything needed to understand and manage disk space on any Linux system.




