I currently have one production machine and one backup machine, and every night I use rsync to backup the important files to my backup server. The directories are getting a bit messy, so I needed to delete old archive files from the directories that I store the backups in. A really neat and simple way to do this is as follows:
find /path/to/backups/ –type f –mtime +30 –exec rm {} \;
The type parameter is telling it to find regular files. From the man page of find:
–type c
File is of type c:
b block (buffered) special
c character (unbuffered) special
d directory
p named pipe (FIFO)
f regular file
l symbolic link; this is never true if the –L option or the –follow option is in effect, unless the symbolic link is broken. If you want to
search for symbolic links when –L is in effect, use –xtype.
s socket
D door (Solaris)
mtime is checking when the last file was modified, and selecting it if it is 30 days or older.
Everything it finds is given to –exec rm {}. The “\;” at the end lets find know where the end of the exec command is.