How to find largest file in linux system ?

Today I received a warning message saying that “/home” directory is almost full. So I thought of cleaning some space after finding largest files in the same directory. I know there are a lot of ways to find it out.

I got below options in my mind, thought of sharing it with you guys.

OPTION 1: Use “find” command with size switch..

For ex: to find files which are larger than 25M

[root@humbles-lap ~]# find . -type f -size +25000k -exec ls -lh {} \; | awk ‘{ print $9 “: ” $5 }’
./kernel-2.6.34.7-61.fc13.src.rpm: 66M
./rpmbuild/SOURCES/linux-2.6.35.tar.bz2: 67M
./kernel-2.6.35.6-48.fc14.src.rpm: 67M
[root@humbles-lap ~]#

OPTION 2: You can list it using “ls” command

For ex:

[root@humbles-lap ~]# ls -lSh
total 140M
-rw-r–r–. 1 root root 67M Oct 27 2010 kernel-2.6.35.6-48.fc14.src.rpm
-rw-r–r–. 1 root root 66M Oct 20 2010 kernel-2.6.34.7-61.fc13.src.rpm

OPTION 3: Using “du” command ..

For ex: Try below command

#du -ah /home/humble/ | sort -n -r | head -n 10


OPTION 4: Using “find” command , but different switch

[root@humbles-lap ~]# find /home/humble/ -type f -exec ls -sh {} \; | sort -n -r | head -5
1020K /home/humble/.mozilla/firefox/mk64jbc4.default/Cache/_CACHE_001_
1004K /home/humble/Desktop/docs/some.ppt
980K /home/humble/Desktop/photos/photo.jpg
968K /home/humble/Desktop/virtio/test.dvi
964K /home/humble/.mozilla/firefox/36bracd3.default/XUL.mfasl
[root@humbles-lap ~]#

As you know you could increase the number of output files by just replacing switch option of “head” command. Also there are other options to make search based on different inputs. Please see #man find for more information on this.

And the number of ways are not restricted… so I am going to stop here 🙂

See you in next blog..