find by Size, Age & Then Act

Filtering by size and time - then doing something

This is where find becomes a superpower: match on size or age, then run a command on every match.

TestMatches
-size +100MLarger than 100 MB (- = smaller)
-mtime -7Modified in the last 7 days
-mtime +30Not modified in over 30 days
-user aliceOwned by alice
-perm 777With exact permissions

Act on results with -exec or -delete:

# The disk-hog ticket, solved:
$ find /var -type f -size +100M -exec ls -lh {} \;

# Delete logs older than 30 days:
$ find /var/log -name '*.log' -mtime +30 -delete

In -exec, {} is each matched file and \; ends the command.

Danger: find ... -delete and -exec rm are irreversible - there is no recycle bin. Always run the search first with -print or ls to see what will match, then add the delete. Pros do this every single time.