Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UNIX: find files for a date range (only in the current directory) 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
Hello,

In UNIX:

I am trying to find files for a date range in the current directory (Not recurssive/No sub-directory search).

Eg.,
I want to list files created between 09/01/2001 and 09/07/2001.

Please help: Unix Guru's out there.

Thanks in advance,

frntan
 
Normally to locate a group of files from a specific date range I would use the find command, however in this situation I think a grep would work better.

ls -l | grep "Sep [1-7]" > output file

Hope that helps
aithosn8
aithosn8@lycos.com
 
aithosn8,
With this command the files created in the past years will also be listed. I want only the files created in the current year (The ex. will be true where the files are created only in the current year).
The approach I took was :

> dummy1
> dummy2

touch -t 200109010000 dummy1
touch -t 200109070000 dummy2

And then I used find command to find the newer than the first file and not -newer from the second file. This lists the date range files - But does not address the search from the current directory.

Any insight on this would be greatly appreciated.
Thanks again.
frntan
 
Here is the two lines you need to distinguish between:
Code:
-rwxr-xr-x    1 root     root         4655 Sep  1 13:29 test1
-rwxr-xr-x    3 root     root         4096 Sep  1  2000 test2
So the difference is that files created on Sep 1-7 in 2001 have the time instead of the year. The following should work.
ls -l | grep "Sep [1-7] ..:" | awk '{print $NF}'
 
This find should do it.

find * -type d -prune -o -newer dummy1 \! -newer dummy2 -print

Hope this helps. CaKiwi
 
CaKiwi,
Thank you. This seems to be working.
Thanks to everyone for shedding light on this problem.
FrnTan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top