Articles

How to Investigate Linux Disk Space

Author: nathacof
Published: Sunday 10th of June 2007

Many times throughout my day I find myself having to clear up some space on our Linux servers. Here I will document those commands that I find useful.

To get a general idea of the space free on all partitions on a system you can run the following command:

nathacof@dev:~/htdocs$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/hdb5              11G  3.8G  6.0G  39% /
nathacof@dev:~/htdocs$

To get a basic idea of the size of the folders within your current working directory you can run the command 'du':

nathacof@dev:/var/www$ du -ms * | sort -n
1       build
1       ccc
1       cgi-bin
1       error
1       icons
1       ncoffield.com
8       htdocs
11      manual
nathacof@dev:/var/www$ 

Want to find log files over a certain size?

[nathacof@vps ~]$ sudo find /var/log -size +2M -exec du -ms '{}' ';' | sort -n
5       /var/log/maillog.4
5       /var/log/secure.1
6       /var/log/secure
6       /var/log/secure.2
8       /var/log/secure.3
40      /var/log/dovecot-info.log
282     /var/log/btmp
[nathacof@vps ~]$

Wow, we've got a pretty big log file (282MB) there. This is actually a binary log of bad login attempts. I threw up some iptables rules to prevent these attempts. So this particular log should no longer be an issue XP.

One thing to note here; you can see that the rotated log files are not being compressed. Logrotate is the utility which handles this log file rotation and we can configure it to compress these logs to save space. Check the manual for further information.

As usual you can find more detailed information on each of these commands using the man command.

Article Search

Social Networks