Checking disk space on linux


You can use df (display free disk space) to troubleshoot disk space issues. While running and maintaining your application on your machine, you might receive an error message signaling a lack of free space on the host. While disk space should be managed and optimized by a sysadmin, you can use df to figure out the existing space in a directory and confirm if you are indeed out of space.


df shows all of the disk space available on the host

Df shows the disk space for each filesystem, its absolute space, and availability.

The -h option prints out the information in human-readable format. The example above shows plenty of disk space on this host.


To retrieve more detailed information about which files use the disk space in a directory, you can use the du command. If you wanted to find out which log takes up the most space in the /var/log directory, for example, you can use du with the -h (human-readable) option and the -s option for the total size.

du -sh /var/log/*
1.8M  /var/log/anaconda
384K  /var/log/audit
4.0K  /var/log/boot.log
0 /var/log/chrony
4.0K  /var/log/cron
4.0K  /var/log/maillog
64K /var/log/messages

The example above reveals the largest directory under /var/log to be /var/log/audit. You can use du in conjunction with df to determine what utilizes the disk space on your application’s host.

Feel free to comment