Check Disk Space Linux Guide: Find and Free Space

· 0x.cloud Team

Check Disk Space Linux Guide: Find and Free Space

To check disk space Linux-wide, run df -h for free space per filesystem, then sudo du -xh --max-depth=1 / | sort -rh | head to see which folders are biggest. Keep drilling into the largest folder until you find the culprit. It's usually logs, the package cache, Docker images or a forgotten backup.

Commands follow the official docs for Ubuntu 24.04 and Debian 12. A full disk breaks databases, Docker and even SSH logins, so deal with it while a few percent are still free.

Check free space with df -h

df -h            # size, used, available, use%, mount point
df -h /          # root filesystem only
df -hT           # adds the filesystem type (ext4, xfs, tmpfs)
df -BG /         # everything in GB, no unit juggling
df -i            # inodes: can run out before space does

Look at the / row and the Use% column. Ignore tmpfs and /boot/efi. If df -i shows 100% while space is free, you have millions of tiny files (sessions or cache, usually).

Why Size isn't Used plus Avail: ext4 reserves about 5% of blocks for root so the system keeps working on a full disk. Regular users hit "No space left on device" once Avail reaches zero, even though Use% reads 95%.

Find what's using space with du

# biggest folders on the root filesystem, staying on this disk (-x)
sudo du -xh --max-depth=1 / 2>/dev/null | sort -rh | head -15
# then go one level deeper
sudo du -xh --max-depth=1 /var | sort -rh | head
# size of a single folder
du -sh ~/projects

If the du total is far below "Used" in df, jump to the section on deleted open files below.

Find individual large files:

sudo find / -xdev -type f -size +500M -exec ls -lh {} \; 2>/dev/null

Easier: ncdu, an interactive viewer that sorts by size and deletes with the d key.

sudo apt install -y ncdu
sudo ncdu -x /

Free up disk space on Ubuntu safely

systemd journal

journalctl --disk-usage
sudo journalctl --vacuum-size=200M     # keep the newest 200 MB

To cap it for good, set SystemMaxUse=200M in /etc/systemd/journald.conf and run sudo systemctl restart systemd-journald. See man journald.conf.

apt cache and old packages

sudo apt clean          # downloaded .deb files in /var/cache/apt
sudo apt autoremove -y  # old kernels and unused dependencies

Old application logs

Rotated logs (*.gz, *.1) in /var/log are safe to delete: sudo find /var/log -name "*.gz" -delete. Don't delete a live log; empty it instead: sudo truncate -s 0 /var/log/app.log.

Snap (Ubuntu)

Snap keeps previous revisions of each package (two by default on Ubuntu; that's refresh.retain=2, and you can't go lower). Old ones are marked disabled, and you can remove them by hand:

snap list --all | awk '/disabled/{print $1, $3}'    # name and revision
sudo snap remove name --revision=number             # remove one old revision

Docker taking up space

Docker is often the biggest consumer: images, stopped containers, build cache and container logs.

docker system df                # images, containers, volumes, build cache
docker image prune -a           # images not used by any container
docker builder prune            # build cache
docker container prune          # stopped containers

docker system prune --volumes also removes unused anonymous volumes (named ones survive; only docker volume prune -a deletes those). Many database images create an anonymous volume when your compose file doesn't name one, and after docker compose down it counts as unused. Check docker volume ls first. Details in the Docker pruning docs.

Container logs with no limit grow to gigabytes. See which containers write the most:

sudo sh -c 'du -sh /var/lib/docker/containers/*/*-json.log' | sort -rh | head -5

Cap them in /etc/docker/daemon.json:

{ "log-driver": "json-file", "log-opts": { "max-size": "10m", "max-file": "3" } }

Then sudo systemctl restart docker; existing containers pick it up once recreated. Setup guide: Docker on Ubuntu 24.04.

Disk full but du disagrees

If df says 100% but du finds far less, a deleted file is still open:

sudo lsof +L1      # files with link count 0, i.e. deleted
# no lsof? sudo apt install -y lsof, or without it:
sudo find /proc/*/fd -ls 2>/dev/null | grep '(deleted)'

Restart the process holding it (sudo systemctl restart your-service) and the space comes back.

Get warned before the disk fills up

Instead of finding out from a crashed database, add a check to your crontab (crontab -e):

# hourly: if the root filesystem is over 90% full, write to a log
0 * * * * [ "$(df --output=pcent / | tail -1 | tr -dc 0-9)" -gt 90 ] && echo "$(date) disk over 90" >> $HOME/disk-alert.log

Swap the log line for a curl call to a Telegram bot if you want a push alert. Schedule syntax, and why a bare percent sign breaks crontab lines: crontab examples.

If you keep running out

  • Set up log rotation (logrotate) and a journal cap.
  • Move data to a separate disk, or grow the current one: mount an additional disk. On 0x.cloud extra NVMe is $0.08 per GB.
  • Move to a plan with a bigger disk. A Docker project (n8n, a database, a bot) often outgrows the 30 GB on s1-2: s2-4 gives 60 GB NVMe and 4 GB RAM for $15.99/month. Compare plans with 15 to 120 GB disks.

A full disk often comes with low memory and high load. Check those too: server load, CPU and memory.

Prompt for an AI agent

Connect to my server and find what's using disk space: show df -h, the top 15 folders by du, and docker system df. Don't delete anything. Propose a safe cleanup list with how much each step frees, and wait for my approval.

Check disk space Linux FAQ

What command shows free disk space in Linux? df -h. It lists size, used, available space and percent used for each filesystem in human-readable units.

How do I check disk space used by a folder in Linux? Run du -sh /path/to/folder. For every subfolder sorted by size, use sudo du -xh --max-depth=1 /path | sort -rh | head.

Why does df say the disk is full when du doesn't? A deleted file is still held open by a process, usually a log. Find it with sudo lsof +L1 and restart that process.

How do I free disk space used by Docker? Check docker system df, then remove what you don't need with docker image prune -a and docker builder prune. docker system prune --volumes also deletes unused anonymous volumes, which can hold database data, so check docker volume ls first.

How much does more disk space cost on 0x.cloud? Extra NVMe is $0.08 per GB; the s2-4 plan with 60 GB NVMe is $15.99/month. Hourly billing never costs more than the monthly price, and deleting a server returns the unused balance.