Skip to content

Linux basicsFor beginnersDuration around 10 min.

How to check disk space in Linux with df and du

If the disk is full, databases stop writing and updates fail. This guide shows you how to check free space, find large folders, and clean up safely.

Tested on with coreutils and ncdu on Ubuntu 24.04 LTS and Ubuntu 26.04 LTS

At a glance

  • df -h shows the size, usage, and free space per filesystem.
  • du -h --max-depth=1 with sort -h leads you folder by folder to what is taking up the space.
  • You can safely free up space with apt clean, apt autoremove, and journalctl --vacuum-size โ€” not by deleting files under /var/lib.

Prerequisites

  • A Linux server with SSH access, such as a VPS or a Cloud Server. df and du are always installed; you need sudo for some folders.

1. Show free space with df

-h prints the sizes in readable G and M. The most important line is usually the one with the mount point /.

Usage of all filesystems
df -h
Example of a server with 80 GB
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        78G   61G   14G  82% /
/dev/vda15      105M  6.1M   99M   6% /boot/efi

With df -h / you only see the root filesystem, with df -hT you also see the type, such as ext4.

2. Find large folders with du

du counts what is in a folder. With --max-depth=1 and sort -h, the largest folders are at the end; -x stays on the root filesystem. Go deeper level by level like this:

Largest folders under /
sudo du -xh --max-depth=1 / 2>/dev/null | sort -h
Deeper into /var and /var/log
sudo du -h --max-depth=1 /var 2>/dev/null | sort -h
sudo du -sh /var/log/* 2>/dev/null | sort -h | tail -5
Example: the logs take up the most space
1.2G	/var/cache
3.8G	/var/lib
9.4G	/var/log
15G	/var

3. Search for large files

find lists all files above a certain size. -xdev stays on the root filesystem and does not search mounted drives.

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

4. More convenient with ncdu

ncdu shows the same numbers as a list that you can navigate with the arrow keys. You can delete directly with d โ€” but only delete what you know for sure. q exits.

Install and start ncdu
sudo apt install -y ncdu
sudo ncdu -x /

5. Clean up safely

These commands only delete what the system no longer needs: the cache of downloaded packages, old kernels, and older parts of the system log.

Package cache and system log
sudo apt clean
sudo apt autoremove
sudo journalctl --disk-usage
sudo journalctl --vacuum-size=200M

What you should not delete

Files under /var/lib belong to running services, such as databases or Docker. Only clean up there using the tools of the respective service; if Docker is running, docker system df shows its share.

Typical errors

  • No space left on device, even though df shows space: You are out of inodes, meaning slots for files โ€” usually caused by millions of small files. df -i shows the usage.
Check inodes
df -i /
  • Space does not return after deleting: A running process is keeping the deleted file open, often a log file. After restarting the service, the space is freed up.
  • du and df show different numbers: df counts the entire filesystem, du only the folders you are allowed to read. Run du with sudo.

We tested all commands in this guide on 2 December 2026 โ€” with coreutils and ncdu on Ubuntu 24.04 LTS and Ubuntu 26.04 LTS. If a step changes at the manufacturer, we update it here along with the date.

Official documentation

Frequently asked questions about storage space

What is the difference between df and du?

df shows the usage of an entire filesystem. du counts how much space a specific folder and its subfolders take up.

At what usage level does it get tight?

You should take action at around 90 percent. Databases and updates need free space to work and will fail otherwise.

Can I delete old logs?

You can shrink the system log with journalctl --vacuum-size. Files under /var/log that end in .gz are old versions that logrotate has already compressed; they can be deleted.

How do I find out early that space is running low?

With monitoring that warns you at a certain threshold. Without additional tools, a daily cron job can check df and send an email.

What should I do if there is generally not enough space?

Move large data to a separate disk or to Object Storage, or choose a plan with more storage.

Further reading

More tutorials

  • The scp command with examples: copy files over SSH

    Linux basicsFor beginnersabout 5 min

    scp copies files over an SSH connection โ€” encrypted, with the same credentials as your login, and without an additional service on the server. This guide shows the commands for common use cases, each with an example to copy.

  • How to check your Ubuntu version, codename and kernel

    Linux basicsFor beginnersabout 2 min

    A single command in the terminal shows which Ubuntu version is running on a server. Here are the common ways with their output โ€” for the version with point release, the codename, the kernel and the architecture.

  • How to remove a directory in Linux with rm and rmdir

    Linux basicsFor beginnersabout 5 min

    In Linux, you delete an empty folder with rmdir and a folder including its contents with rm -r. This tutorial shows both commands with their messages, the variants with and without prompting, and what to check before running rm -rf โ€” because there is no recycle bin in the terminal.

More space for your data

If disk space is constantly running low: additional storage as a separate drive or Object Storage.