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

[terminal]
[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 ~]#
[/terminal]

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

For ex:
[terminal]
[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
[/terminal]

OPTION 3: Using “du” command ..

For ex: Try below command

[terminal]

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

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

[terminal]
[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 ~]#
[terminal]

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

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

See you in the next blog.