How to find the largest directories/files on Linux/Unix/BSD

In the course of using VPS/Server, sometimes you will need to remove file or folder capacity not used to log to save hard drive space. 3 using the following command you can easily find data are accounted for the majority of the hard drive to be able to delete it.

The du command: Determining storage usage
Sort order: sort the lines of text file or input data
Head command: output data from the top down, for example, took 10 first line such

Use the command below to find 10 file/directory has the largest capacity:

du -a /var | sort -n -r | head -n 10

Out put

1008372 /var
313236 /var/www
253964 /var/log
192544 /var/lib
152628 /var/spool
152508 /var/spool/squid
136524 /var/spool/squid/00
95736 /var/log/mrtg.log
74688 /var/log/squid
62544 /var/cache

If you want to convert the information bytes into MEGABYTES, KB, use the following command:

cd /path/to/some/where
du -hsx * | sort -rh | head -10

The above command only when the operating system is installed the sort, if not then you can use the following command:

for i in G M K; do du -ah | grep [0-9]$i | sort -nr -k 1; done | head -n 11

out put

179M .
84M ./uploads
57M ./images
51M ./images/faq
49M ./images/faq/2013
48M ./uploads/cms
37M ./videos/faq/2013/12
37M ./videos/faq/2013
37M ./videos/faq
37M ./videos
36M ./uploads/faq

Leave a Reply

Your email address will not be published.