find with -exec: files older than x day

You can easily move files of a certain age to a different location (for example backup tape or network share)

In this example you will search for files only (-type f) which are older than 30 days (-mtime +30) and execute the move command for each file returned. This list of files is represented by the {} brackets.

find /path/to/source/ -mtime +30 -type f -exec mv {} /path/to/destination ;

Another example shows that you can use the {} brackets in every command you like.

This example below returns all files which name ends with .sql and which are bigger than 5MB and adds/updates them to a specific tar file

find /path/to/src/ -size +5M -name "*.sql" -exec tar -uvf /backup/my-archive.tar {} ;

You can combine several filters in ‘find’ (check the man page) and use every command so this is really powerful.