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

| | 1 min read

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.