Linux VPS

Check disk usage on Linux with df, du and ncdu

Find out how full your Linux VPS disk is with df, see which folders use the space with du, and browse it interactively with ncdu before cleaning up.

BeginnerLinux VPS2 min read

A full disk stops databases, breaks updates and takes websites offline. Three commands tell you everything: df shows how full each filesystem is, du shows how big folders are, and ncdu lets you browse usage interactively.

Before you start

  • SSH access to your VPS (see connect with SSH).
  • sudo rights, so you can read every folder.

See free space with df

df -h

Check the Use% column for /. Above 90% you should clean up soon; at 100% services start failing. -h prints sizes in G and M. To show only real disks:

df -h -x tmpfs -x devtmpfs

Check inodes too

df -i

Every file uses one inode. Millions of tiny files (cache, session or mail files) can exhaust inodes while space remains, giving "No space left on device" with free gigabytes.

Find big folders with du

sudo du -h --max-depth=1 / 2>/dev/null | sort -h

Then drill into the largest one, for example /var:

sudo du -h --max-depth=1 /var | sort -h

Show the size of one folder only with du -sh /var/log.

Browse interactively with ncdu

sudo apt install ncdu
sudo dnf install ncdu
sudo ncdu -x /

Use the arrow keys and Enter to move through folders, sorted by size. -x stays on one filesystem. Pressing d deletes the selected item, so be careful; q quits.

Usual space hogs

LocationWhat it isSafe action
/var/logLogs and the systemd journalsudo journalctl --vacuum-size=500M, check logrotate
/var/cache/apt or /var/cache/dnfDownloaded packagessudo apt clean or sudo dnf clean all
/var/lib/dockerImages and containersSee docker prune
/home, /backupOld archives and backupsMove off-server, then delete

Warning: Deleting a log file that a service still writes to does not free the space until the service restarts. Empty it instead: sudo truncate -s 0 /path/file.log.

Troubleshooting

  • df says full, du finds little: a deleted file is still held open. Find it with sudo lsof +L1 and restart that service.
  • Permission denied lines: run du with sudo, or add 2>/dev/null.

Next steps

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.