1

I wanted to display the list of files from particular date. Suppose I have 4 files on particular dir..

AA (Created on 01-Oct-2015)
BB (Created on 01-Oct-2016)
CC (Created on 01-Oct-2017)
DD (Created on 01-Oct-2017)

And if i pass the From date parameter as 01-Nov-2015 So it should display list of files from that date like > 01-Nov-2015 for above parameter it will print

BB
CC
DD   

files only

Srini V
  • 11,045
  • 14
  • 66
  • 89

2 Answers2

0

You can use, if your find supports it (version >= 4.3.3) its -newerXY parameter and provide a date.

Example:

find /tmp -newermt 01-Oct-2016

From the man page:

-newerXY reference

Succeeds if timestamp X of the file being considered is newer than timestamp Y of the file reference. The letters X and Y can be any of the following letters:

a The access time of the file reference

B The birth time of the file reference

c The inode status change time of reference

m The modification time of the file reference

t reference is interpreted directly as a time

An official workaround is to create a file with the proper timestamp:

touch -t 02010000 /tmp/stamp
find /usr -newer /tmp/stamp
rm -f /tmp/stamp

in your case, use date to get the matching timestamp like this

touch -d 10-Oct-2017 /tmp/stamp
find /usr -newer /tmp/stamp
rm -f /tmp/stamp

As a side note, you may want to find files more recent than BB using:

find -anewer BB
Zermingore
  • 743
  • 2
  • 11
  • 28
  • Thanks for your quick response. It is giving below erro find: invalid predicate `-newermt' I am using GNU bash, version 3.00.15(1) I am using below code to find the files , so is possible to add the Date from parameter so it will give the files greater than the date from paramter [CODE] echo "$XX-TOP/AP/in/123" cd $XX-TOP/AP/in/123/AP/in/000723 find . -type f -print -maxdepth 1 | sed -e 's;[^/]*/;|____;g;s;____|; |;g' – Nilesh Tabhane Oct 13 '17 at 11:11
  • I updated my answer with a workaround for `find` older than 4.3.3 – Zermingore Oct 13 '17 at 11:21
  • Hello,Thanks for your help. I am using below code to get the number of days. [CODE] today_date=$(date +%d/%m/%Y) mm=$5 dd=$(date -d"$mm" +%d/%m/%Y) echo [[ $(( ($today_date - $dd) / (60 * 60 * 24) ))]]. So I am getting below error " value too great for base (error token is "08")" I am having Todays Date: 16/10/2017 and Date From : 11/08/2017. I tried with adding 10# to the both the dates but still getting same error. Thanks in advance – Nilesh Tabhane Oct 16 '17 at 09:33
0

You can use another option in find with more compatibility:

find . -type f -name "something" -mtime +15 ("number of days")

But you have to calculate the number of days between the actual date and the date than you're expecting, dont accept a date only a number.

  • Hello,Thanks for your help. I am using below code to get the number of days. [CODE] today_date=$(date +%d/%m/%Y) mm=$5 dd=$(date -d"$mm" +%d/%m/%Y) echo [[ $(( ($today_date - $dd) / (60 * 60 * 24) ))]]. So I am getting below error " value too great for base (error token is "08")" I am having Todays Date: 16/10/2017 and Date From : 11/08/2017. I tried with adding 10# to the both the dates but still getting same error. Thanks in advance – Nilesh Tabhane Oct 16 '17 at 09:26