3

I have a folder in which there are very old files. It contains files since 2009 and they are dump files with error log.

What I want to know is if it is possible to delete the files between let's say 2009 and 2011. Something like:

delete 'file_patern' between 2009-2011 and 2012-2014

I want to preserve for example 2010, 2015 and current year.

Machine is running on RedHat.

4

To list all files that were modified between 2009 and 2011, use find with -newermt:

 find . -type f -newermt '01 jan 2009 00:00:00' -not -newermt '01 jan 2012 00:00:00' -ls

To remove:

find . -type f -newermt '01 jan 2009 00:00:00' -not -newermt '01 jan 2012 00:00:00' -delete

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.