39

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
75

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

| improve this answer | |
22

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

| improve this answer | |
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.

0

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
| improve this answer | |

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.