Recursively remove files those size is less than 1MB

How do I recursively remove files that are less than 1MB in size from a directory?


Solution 1:

This can be done with find:

find . -type f -size -1M -exec rm {} +

Note that this will recursively descend into subdirectories, and will unconditionally delete all files smaller than 1 megabyte. Be careful.

Solution 2:

This should do the job:

$ find <directory> -type f -size -1M -delete

Solution 3:

Just for variety and a possible (probably marginal) performance gain:

find <directory> -type f -size -1M -print0  | xargs -0 rm