How to check what is taking up all the disk space on Ubuntu
Here are a few things you can try:
Note: Depending on the size, these commands can take a while to complete.
1) Run df command:
df -h /
2) Run du command:
du -hs /
If it takes a long time, you can try checking sub directories instead to narrow down the issue:
du -hs /var/log
du -hs /var/www
du -hs /opt
sudo du -h --max-depth=1 / | sort -hr | head -n 10
sudo du -h --max-depth=1 /var/lib | sort -hr | head -n 10
3) Run ncdu command:
apt update
apt install ncdu
ncdu /
4) If docker is taking up the space:
Check with du and sort it:
sudo du -h --max-depth=1 /var/lib/docker | sort -hr | head -n 10
sudo du -h --max-depth=1 /var/lib/docker/containers/ | sort -hr | head -n 10
Docker Disk Space Commands Cheat Sheet:
| Command | Description |
|---|---|
docker system df | Show Docker disk usage |
docker system prune | Clean up Docker system |
docker container prune | Remove unused containers |
docker image prune | Remove unused images |
docker volume prune | Remove unused volumes |
docker network prune | Remove unused networks |
docker builder prune | Remove unused build cache |