Knowledgebase

Find frequently asked questions and setup guides by searching or by browsing the categories.

See Free Space with df

df -h

The -h flag prints sizes in megabytes and gigabytes. Each line is one filesystem:

ColumnMeaning
FilesystemThe disk or partition, for example /dev/vda1.
Size, Used, AvailTotal size, space in use, and space still free.
Use%How full it is. Above about 90%, plan a cleanup.
Mounted onWhere it appears in the folder tree. / is the main disk.

Lines for tmpfs and devtmpfs are memory, not disk; ignore them. To check one path only, name it: df -h /var. To see the filesystem type as well, use df -hT.

Find What Uses the Space with du

Size of one folder:

sudo du -sh /var/log

The largest folders one level below a path, sorted:

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

Start at /, then repeat the command inside the biggest folder until you reach the cause. Add -x to stay on one filesystem.

Find Large Files

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

For an interactive view, install ncdu and run sudo ncdu -x /: it shows folders by size and lets you walk through them with the arrow keys.

Check Inodes Too

A disk can refuse new files while df still shows free space. Each file uses one inode, and a filesystem has a fixed number of them. Millions of small files, such as session or cache files, can use them all:

df -i

If IUse% is near 100, look for a folder with a very large number of files.

Space That Does Not Come Back

If you delete a large log and df shows no change, a running program still holds the file open. List such files:

sudo lsof +L1

Restarting the service named in the output releases the space.

Safe Ways to Free Space

  • System journal: sudo journalctl --vacuum-size=200M trims old journal entries.
  • Package cache: sudo apt clean on Ubuntu and Debian, sudo dnf clean all on AlmaLinux and Rocky Linux.
  • Unused packages and old kernels: sudo apt autoremove.
  • Rotated logs: old .gz files in /var/log can go; check that logrotate is active for your own application logs.
  • Docker: docker system df shows what images and stopped containers use; docker system prune removes what is unused.
  • Old backups and archives: move them off the server before you delete them.

Do not delete files in /var/lib by hand to save space: databases and package managers keep live data there.

See the Disks Themselves

lsblk

lsblk lists disks and partitions with their sizes. If the disk is larger than the filesystem on it, for example after a plan upgrade, the partition and filesystem still have to be grown before df shows the new space.

Was this answer helpful?
Loading...