This is a quick tutorial around linux disk space usage on your VPS. If your VPS isn’t responding as it should one of the problems that you may have run into is that you are out of disk space. If your not sure the way to check how much disk you are using is issuing the df -kh command as follows
[[email protected] ~]# df -kh
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 9.9G 1.1G 8.4G 11% /
tmpfs 257M 0 257M 0% /dev/shm
As you can see above this server is sitting at 11% of disk space used. The server below is using all of it’s capacity
[[email protected] ~]# df -kh
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 9.9G 9.9G 8.4G 100% /
tmpfs 257M 0 257M 0% /dev/shm
Often the problem with disk space is that you have unmonitored log files that have grown slowly over time or suddenly due to some other error. Our standard approach to this problem is to find the biggest files on your file system and work from there. We suggest starting with a find command to search for all files over say 100MB for example on a server with no large file you will see this.
[[email protected] /]# find / -type f -size +100000k
[[email protected] /]#
If the server has large files larger than 100MB you will see something like the following.
[[email protected] /]# find / -type f -size +100000k
/var/lib/mysql/eximstats/smtp.MYI
/var/lib/mysql/eximstats/smtp.MYD
/var/lib/mysql/eximstats/sends.MYD
/var/lib/mysql/eximstats/defers.MYI
/var/lib/mysql/eximstats/failures.MYI
/var/lib/mysql/eximstats/sends.MYI
/var/lib/mysql/eximstats/failures.MYD
/var/lib/mysql/eximstats/defers.MYD
/var/log/exim_mainlog
[[email protected] /]#
In this example you can see that the eximstats database and log files have grown quite large and in this scenario needed to be cleaned up to return the used space.
Another command that we use quite regularly in these circumstances is the du (disk usage) command. If you issue the du command it will show you the size of all of the directories including their contents which can be very handy in seeing where all your disk space is being used up. For Example
[[email protected] /]# du -h / --max-depth=1
4.0K /srv
0 /net
4.0K /mnt
7.2M /bin
47M /etc
4.0K /opt
4.0K /selinux
8.0K /tmp
0 /misc
4.0K /home
125M /lib
4.0K /media
0 /sys
33M /sbin
44K /dev
60K /root
35M /var
16K /lost+found
622M /usr
16M /boot
0 /proc
882M /
[[email protected] /]#
In the example above this has been set to a depth of 1 so it will only show you the first level directories and the -h command will format the Sizes to be human readable.
If you know of any other useful commands or techniques, please let us know below in the comments.