We use cookies to keep our site relevant and easy to use, your continued use of this site is consent that we may set several cookies (see our Privacy & Cookie Policy), click to always allow cookies from our site (and not see this notifcation on your next visit) or read more.Allow Cookies

EU legislation requires that all websites clearly specify if cookies are being used and their purpose, You can read more about how we use cookies (and which cookies we use) in our Privacy and Cookie Policy.

You will see this notification the first time you visit our website unless you accept cookies (in which case we'll set a cookie to remember thay you're happy for us to to set cookies!).

Linux : Delete files older than specific date with a specific extension

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).

This entry was posted on Thursday, December 11th, 2014 at 12:09 pm and is filed under Linux. You can follow any responses to this entry through the RSS 2.0 feed.