How to Check Disk Space on Linux
You check the disk space of your Linux server with the df -h command. With du and ncdu you then find out which folders and files take up the most space. In this article you read how to view free space, track down large files and safely free up space on your VPS.
Viewing free disk space with df
With df you see per partition how much space there is in total, how much is in use and how much is still free:
df -h The -h option shows the values in readable units, such as G for gigabyte. Look mainly at the line with / in the Mounted on column: that is the main disk of your server.
Viewing folder sizes with du
With du you see how much space a folder takes up. This command shows the largest folders in the root folder, sorted from large to small:
du -h --max-depth=1 / 2>/dev/null | sort -hr | head -15 Then dig further into the largest folder, for example /var, until you have found the cause.
Searching quickly with ncdu
Ncdu is a clear program that lets you browse through your folders with the arrow keys and immediately see what uses the most space:
apt install ncdu -y
ncdu / On AlmaLinux you install it with dnf install ncdu -y.
Finding large files
With find you search for all files larger than a certain size, for example 500 MB:
find / -type f -size +500M -exec ls -lh {} \; 2>/dev/null Freeing up space safely
- Clean up old packages: remove packages that are no longer needed with
apt autoremove -yand empty the package cache withapt clean. - Limit log files: the system journal can grow considerably. Limit it with
journalctl --vacuum-size=200M. - Clean up Docker: if you use Docker, remove unused images and containers with
docker system prune. - Old backups: check whether there are old backups on the server that you have already stored elsewhere.
Never delete files if you are not sure what they do, especially not in /usr, /lib or /etc. If in doubt, take a snapshot first.
Disk full: what now?
If your disk is completely full, services such as your web server or database can stop. First free up some space with the steps above. If you structurally need more storage, you simply move to a larger VPS plan.
Related articles
Rent a Linux VPS with root access
Ubuntu, Debian or AlmaLinux with full root access via SSH, enterprise Ceph storage with high availability and hosting in Amsterdam.