LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Using FIND to locate files created between certain dates (https://www.linuxquestions.org/questions/programming-9/using-find-to-locate-files-created-between-certain-dates-343569/)

billybobjoe1984 07-15-2005 05:37 PM

Using FIND to locate files created between certain dates
 
Hello everyone,

I am trying to make a script that will locate all files files matching a particular name "*x*" that were created between two dates so that I can then grep them for a particular string. I am currently using this script:

/bin/find ./ -ctime -31 -name "*x*" -exec /bin/cat {} ";" | /bin/grep y >> file

but my requirements have changed so I can't look for files created between last month and today, but rather between two past dates. Thanks for any assistance!

keefaz 07-15-2005 06:18 PM

There is no creation time for a file in UNIX systems
instead you have :
- time of last access
- time of last modification
- time of last status change

You surelly want time of last modification which is mtime

billybobjoe1984 07-15-2005 06:48 PM

Er, yeah -ctime isn't creation time but changed time, sorry for the misunderstanding. I was looking at mtime but it still doesn't look like it will support a range of dates either, only from the past till now. I need it to find files changed/modified between two past dates. Thanks for replying.

keefaz 07-15-2005 07:08 PM

You could use -newer file and you touch a file
with the most ancient date and the other as :

1st date : 1/6/2005 12:00
2nd : 12/7/2005 12:00
Code:

touch -t 200506011200 first
touch -t 200507121200 last

find / -newer first ! -newer last


eddiebaby1023 07-16-2005 11:30 AM

Quote:

Originally posted by billybobjoe1984
Er, yeah -ctime isn't creation time but changed time, sorry for the misunderstanding.
Just to clarify, -c is the time the inode entry was last changed, -m is the time the data in the file was last changed.

billybobjoe1984 07-21-2005 04:26 PM

Quote:

Originally posted by keefaz
You could use -newer file and you touch a file
with the most ancient date and the other as :

1st date : 1/6/2005 12:00
2nd : 12/7/2005 12:00
Code:

touch -t 200506011200 first
touch -t 200507121200 last

find / -newer first ! -newer last


Thanks, I'll give this a try!

mlp68 07-23-2005 07:07 PM

find takes multiple selectors

e.g. find files that were modified yesterday:

find . -mtime +1 -mtime -3

so, older than 1 day but younger than 3. Works with ctime, atime, mmin etc as well.

I think that's your ticket.

You can chain all kinds of selection statements like that.

mlp


All times are GMT -5. The time now is 12:00 PM.