Sometimes we are clueless which directories are eating up all the disk space on our Linux Server. There are few ways to find them out.
Most of the directories that’s particularly growing up are /var, /tmp, or /home
1. Type the following command at the shell prompt to find out top 10 largest file/directories:
[root@server1 ~]# du -a /var | sort -n -r | head -n 10
du : Estimate file space usage.
sort : Sort lines of text files or given input data.
head : Output the first part of files i.e. to display first 10 largest file.
Output:
13075456 /var 9078732 /var/www 4351176 /var/log/ 3769656 /var/lib 2677596 /var/log/btmp 2466664 /var/lib/awstats 1328512 /var/log/httpd 1213832 /var/lib/varnish 1049600 /var/lib/varnish/varnish_storage.bin 682296 /var/lib/awstats/awstats082012.txt
2. If you want more human readable output try:
[root@server1 ~]# cd /var [root@server1 var]# du -hsx * | sort -r | head -10 # SAMPLE OUTPUT 96M tmp 8.7G log 8.4M db 8.0K racoon 8.0K preserve 8.0K opt 8.0K nis 8.0K net-snmp 8.0K local 8.0K games
Where,
du command -h option : display sizes in human readable format (e.g., 1K, 234M, 2G).
du command -s option : show only a total for each argument (summary).
du command -x option : skip directories on different file systems.
sort command -r option : reverse the result of comparisons.
head command -10 OR -n 10 option : show the first 10 lines.
3. Finding directories over 1GB
[root@server1 ~]# du -h / | grep ^[0-9.]*G # SAMPLE OUTPUT 2.4G /var/lib/awstats 1.2G /var/lib/varnish 3.6G /var/lib 1.3G /var/log/httpd 4.2G /var/log/varnish 8.8G /var/log 13G /var 1.4G /usr 15G /opt 122G /data 2.8G /root 2.2G /home/user
4. To find directories over 10GB and sort the output with the largest directories on top
[root@server1 ~]# du -h / | grep ^[1-9][0-9][0-9.]*G | sort -rn
5. To find directories over 200GB
[root@server1 ~]# du -h / | grep ^[2-9][0-9][0-9][0-9.]*G
var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-37138722-1']); _gaq.push(['_trackPageview']);
(function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();