X
X
X
X

Knowledge Base

HomepageKnowledge BaseServer ManagementHow to Check Disk Usage on Linux: F...

How to Check Disk Usage on Linux: Find What Fills the Disk with df and du

In short: To check disk usage on Linux, first run df -h to see which partition is full, then use du to find which folder takes the most space on it. df shows the overall state of the disk and du shows folder sizes. Use lsof +L1 for deleted files that are still held open and journalctl --vacuum-size for old system logs.

When a disk fills up, databases cannot write, email is rejected and websites start returning errors. You can run the commands in this guide after you connect to your server over SSH. They are the same on common distributions such as Ubuntu, Debian, AlmaLinux and Rocky Linux.

Check disk usage on Linux with df

The df command shows the size, used space and free space of mounted file systems. The -h option prints sizes in readable units (G, M):

df -h

Look at the Use% and Mounted on columns. For example, the line /dev/vda1 40G 38G 2.0G 95% / means the partition holding the root directory is 95 percent full. To see the file system type as well, use df -hT.

Sometimes you get a "No space left on device" error even though df -h shows free space. A common reason is that the inodes have run out: a large number of small files has used up the entries reserved for files. Check it like this:

df -i

Check disk usage on Linux: df -h shows a 95 percent full disk, du finds the biggest folder, plus lsof +L1

Find the folder that takes the space with du

du calculates how much space folders use on disk. Instead of scanning a big folder all at once, go one level deeper at a time:

sudo du -xh -d 1 / | sort -h
  • -h: prints sizes in readable units.
  • -d 1: shows totals only for folders one level down.
  • -x: stays on one file system, so only the full partition is scanned.
  • sort -h: sorts the results by size from small to large, so the biggest folder is at the bottom.

Once you find the biggest folder, repeat the command for it, for example sudo du -xh -d 1 /var | sort -h. To see the total of a single folder, du -sh /var/log is enough. The usual suspects are logs (/var/log), backup files, package caches and application upload folders.

Safe cleanup steps

  1. Limit system logs: run journalctl --disk-usage to see how much space systemd logs use. To shrink old archived logs below a given size:
sudo journalctl --vacuum-size=500M

According to the journalctl manual, this only removes archived journal files and leaves active ones alone.

  1. Clean the package cache: on Ubuntu and Debian, sudo apt clean, and on AlmaLinux and Rocky Linux, sudo dnf clean all removes downloaded package files. Installed packages are not affected.
  2. Move old backups: before deleting old backup files stored on the server, make sure they have been copied somewhere else.
  3. Find deleted files that are still open: if you deleted a file but the space was not freed, a process may still be holding it open. List those files with lsof:
sudo lsof +L1

The output shows the service holding the file. The space is freed when the service releases it; restarting the service with systemctl is usually enough.

Caution: do not delete database files under /var/lib or any file you are not sure about by hand. When in doubt, take a backup first or ask our support team.

Keep the disk from filling up again

Checking disk usage regularly lets you spot the problem before errors appear. To track disk usage together with CPU and RAM, see our guide on how to monitor server resource usage. Make sure log files are rotated and old backups are removed automatically. If the disk fills up again soon after a cleanup, you may need a bigger disk or plan rather than more cleanup.

Frequently Asked Questions

Why do df and du show different results?

df shows the overall state of the file system, while du adds up the files it can reach. Deleted files that are still open keep using space in df but do not appear in du. You can find them with lsof +L1.

The disk looks free but I cannot create files. Why?

The inodes may have run out. Check with df -i. A large number of small files, such as old session or cache files, is usually the reason.

Can I delete files in /var/log?

You can delete old archived logs, but instead of deleting active log files it is safer to use tools such as journalctl --vacuum-size and log rotation.

Can't find the information you are looking for?

Create a Support Ticket
Did you find it useful?
(6 times viewed / 0 people found it helpful)

Powered by WISECP
Top