How can I Get a list of all files modified , say 3 months ago.
I checked this question but I was not able to apply it to my scenario.
I am trying this now , it seems to be working , but I know there should be a better way using find.
ls -ltR | grep -v '2011-05' | grep -v '2011-06' | grep -v '2011-07' | grep -v '2011-08
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
One solution is: find . -type f -mtime 90
That finds files that was last modified 90 days ago (in those 24 hours that started 91 x 24 hours ago and ended 90 x 24 hours ago).
find . -type f -mtime -90
finds files that were modified in the last 90 days (or in the future).
find . -type f -mtime +90
finds files that were modified at least 91 days ago (at least in POSIX compliant find
implementations).
Method 2
As @hknik says, the -mtime
operation on find
is likely your best bet, but if you want to get all files around three months ago, then you need a bigger net:
find . -type f -mtime -105 -mtime +76
This will find the regular files in the month surrounding three months ago, between 11 and 15 weeks ago.
(note the 76 instead of 7 x 11 = 77, as you want files whose age rounded down to an integer number of days is strictly greater than 76 to get files that are at least 77 days (11 weeks) old).
Method 3
With zsh
and (.m[-|+]n)
glob-qualifiers:
print -rl -- *(.m90)
will list files modified 90 days ago (in those 24 hours that started 91 x 24 hours ago and ended 90 x 24 hours ago like with POSIX
find -mtime 90
).print -rl -- *(.m-90)
will list files modified in the last 90 days (or in the future),
print -rl -- *(.m-100m+90)
will list files modified between 91 and 100 days ago.
Method 4
You can use “3 months ago” directly with the “newerXY” syntax:
find . -maxdepth 2 -xdev -type f -newermt '3 months ago'
(I added
maxdepth
and xdev
to limit the search)
With these relative dates minutes, hours, days, weeks and months can be used.
“m” stands for modification time, “t” means direct time (and not the date of a reference file).
Or by combining two absolute dates to choose a time span; here from Jan 1 to Jan 15:
#] find . -maxdepth 2 -newermt 'Jan 1' ! -newermt 'Jan 15' -ls 415640 4 -rw-r--r-- 1 root root 2190 Jan 8 15:14 ./df.man 412465 4 -rw-r--r-- 1 root root 98 Jan 1 2020 ./ranfunc 412282 4 -rw------- 1 root root 23 Jan 13 16:53 ./.python_history 406542 0 lrwxrwxrwx 1 root root 56 Jan 8 19:46 ./.fvwm/.BGdefault -> /usr/share/fvwm/default-config/images/background/bg3.png 417900 28 -rw-r--r-- 1 root root 25990 Jan 3 09:48 ./xterm.2020.01.03.09.48.03.xhtml
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0