Skillett.com

Today I needed to find a bunch of files that hadn’t been touched in a while and had a very specific extension on one of our servers.

A bit of googling and I came up with this, use this to check which files would be removed:

find . -mtime +365 -type f -name "*.jpg" -exec ls -la {} \;

And this to delete the files:

find . -mtime +365 -type f -name "*.jpg" -exec rm {} \;

For this you’ll need to be in the directory in question (or replace the . after the find with the directory name).

-mtime is the modification time, we’ve set this to 365 days ago.
-type is set t files
-name is all the jpegs.
-exec is the command to run (in the first case list all the files details, and in the second case remove the file).