Find and delete files greater than a given size from the Linux command line

The find command available in GNU/Linux shells is a versatile tool for finding files matching the given conditions in a folder and performing a specific action on the files found. The following command will find all files greater than 1M size in your current folder and ask you if you would like to delete the file

find . -size +1M -exec rm -i {} \;

The following command will find all tar.gz files greater than 1M size and ask you whether you wish to delete them.

find . -size +1M -name "*.tar.gz" -exec rm -i {} \;

The following command will find all tar.gz files greater than 1M size and less than 20M size and ask you whether you wish to delete them.

find . -size +1M -name -size -20M "*.tar.gz" -exec rm -i {} \;

Find is an extremely powerful tool. To know more check out man find and read through the full set of offerings.

Views (20)

Share on Facebook0Share on Google+0Share on LinkedIn0Tweet about this on TwitterEmail this to someonePrint this page
[Total: 1    Average: 5/5]

Leave a Reply

Your email address will not be published. Required fields are marked *

twenty − seven =