How to find files over X days old on Linux

This has come up a few times and I thought I would share it.

If you need to find files in a directory over 60 days old

/usr/bin/find /directory/to/look/in -atime +60


This has come in hand to periodically delete log files. To take it one step further try this one.

/usr/bin/find /directory/to/look/in -atime +60 -exec ls -al {} \;


This will look in the directory specified for files over 60 days old and then do a ls -al on those files. You can adjust the command as needed to archive, copy, or even delete the files.

It can be added to a cron job to run.

To see some of my other helpful command line posts click here.

Labels: , ,