Finding large files from the Command Line

A couple of days ago, one of the servers running an application that I used to maintain ran out of disk space… the problem was that the app was logging a lot of stuff and there were log files with sizes around 2 GB.

Of course at the beginning we didn’t know where all the space was gone, so we had to find which files were causing the trouble.

In Linux using find you can search for files with an specified size and then execute some command for each one of them.

Example: finding files with size greater than 100 MB and print its information.

find [path] -type f -size +100M -ls

And if you want to execute a command to each one of the files you can specify the param -exec option or using instead -ok you get more control over what it will do.

Example: find and remove all the files under the home that have a size greater than 500MB.

find $HOME -type f -size +500M -ok rm {} \;

{} will be replaced for the path of each file