find
has good support for finding files the more modified less than X days ago, but how can I use find
to locate all files modified before a certain date?
I can't find anything in the find
man page to do this, only to compare against another files time or to check for differences between created time and now. Is making a file with the desired time and comparing against that the only way to do this?
No, you can use a date/time string.
From
man find
:Example:
Not directly related to question, but might be interesting for some that stumble here.
find command doesn't directly support -older parameter for finding files older than some required date, but you can use negate statement (using accepted answer example):
will return files older than provided date.
If you have only '-newer file' then you can use this workaround:
man touch:
Assuming that your touch has this option (mine is touch 5.97).
this find command will find files modified within the last 20 days.
You acan add additional limitations like:
the same as before, but only finds files ending with '.txt'.
Just to add on - you may even use two newermt arguments to search in a time interval:
to find all files from march 2007.
like this:
This will give you files older than 01-01-2015 in your current directory.
https://muzaffarmahmoodblog.wordpress.com/2019/07/11/linux-command-to-remove-files-older-than-2015-in-a-directory/
You could use a script like this
Save it in your $PATH as "newerthan" and make it executable.
Then you can find file modified after a certain date like this:
or
or
That should do what you want. I don't think there is a built in way to achieve this otherwise.
if your date is formatted such that its ok for comparison,
Is the correct answer to this question (find files modified before the last 20 days).