Finding large files on Linux/Unix
Depending on how you build your filesystem, locating large files such as logs or other output from scripts, programs, or daemons can be frustrating at best. Since I'm not a GUI kind of guy this little snippet for the shell can save tons of time. (tested with KSH and Bash shells, likely should work with most if not all)
-
find / -type f -size +20000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
This will search beginning at the root / directory for all files over 20M. To adapt it for your use simply change the / to represent any beginning path you wish and the 20000k to the minimum filesize you would like to find.
Hard to get any easier than this. A detailed description of the all powerful awk can be found by reading the associated man pages should you be so inclined.
Happy hacking!
February 11th, 2008 at 4:46 am
Hello,
thank you for this intersting and usefull command.
I’ve found a shorter expression for this, but I think it works only with Linux ls :
find / -type f -size +20000k -exec ls -sh {} \;
February 21st, 2008 at 11:15 am
Hi Don,
I’ve tested your command on Solaris 10, and it does work there as well, output seems a bit slower but that could be related to server load at the moment here.
None the less I’ve added your version to my .bash_aliases and .alias files too. That should be taken as a compliment of the highest order! Very few folks make it to my login scripts both at home and the office!
Thanks!
Dave
March 26th, 2008 at 5:19 am
Thank you for the adding in your bashrc.
On my side, your blog has the great privilege to be added on my netvibes (but unfortunatly I haven’t added the comment flux, that’s why I reply one month later. shame on me :P)
For the command the problem of compatibility between Solaris and GNU commands is very recurent.
Try this one, peraps it’ll work better :
find / -type f -size +20000k | xargs ls -sh