eTechtips

Tech Tips and Insights

Utility: Find files files older than a certain amount of days

/ ,

I had to write a backup script the other day and used the find command to find the files that were older than a given amount of days.

DAYS_TO_KEEP=7
find /path/to/files* -type f -name *.bak -mtime $DAYS_TO_KEEP -exec rm {} ;

The -name argument uses the escaped asterisk so command completion does not replace it with all the file names.

The -mtime argument takes a number that is the number of days to look at.

The -exec argument takes a command and the {} is replaced with the current file name and the ; is the end of the command.

This is a small part of the power of the find command.

Loading

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.