using find cmd to locate files by date

using find cmd to locate files by date

Post by Do » Tue, 10 Aug 1999 04:00:00



To anyone who is knowledgable in advanced unix cmds:

I need to be able to do a find that prints out all of the files into a
log file but the find must be able to find certain files that fall
within a certain date range.  How do I do this? I checked the man
pages out on find but there is no criteria that states a date range.
I found one however that checks within the last x number of days
(-mtime).    but that is not what I need.    
any help would be GREATLY appreciated !
-LInda

 
 
 

using find cmd to locate files by date

Post by Barry Margoli » Tue, 10 Aug 1999 04:00:00




>To anyone who is knowledgable in advanced unix cmds:

>I need to be able to do a find that prints out all of the files into a
>log file but the find must be able to find certain files that fall
>within a certain date range.  How do I do this? I checked the man
>pages out on find but there is no criteria that states a date range.
>I found one however that checks within the last x number of days
>(-mtime).    but that is not what I need.    
>any help would be GREATLY appreciated !

You simply have to convert the date range into the appropriate date offset.
For instance, if you need to find files modified between Aug 1 and Aug 5,
inclusive, and today is Aug 9, you do:

find -mtime -9 -mtime +3

Another thing you could do is convert your find command to Perl with
find2perl, and then modify the resulting Perl script to do the date
comparisons that you want.

--

GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

using find cmd to locate files by date

Post by RobertQuir » Tue, 10 Aug 1999 04:00:00


I don't fully understand your requirement but I hope this is your
requirement:

Supply two dates in a fixed known format and find files which fall between
these
two dates. Don't differentiate between creation, modification or access
time ie. take the timestamps that appear in a long listing of a directory.

I do not know of one command which will do this either but it isn't too hard
to write a shell script ( after all unix is for programmers ! )

The idea is to 'touch' two temporary files - one with the 'from date' the
other
with the 'to date' then find files which are older than the first file but
newer
than the second file.

On my linux system ( and many other unix systems ) you can then shell
script the following:

# --- SCRIPT START ---

#!/bin/sh

# touch MMDDhhmm file
# eg. the 'start'  file is touched 1 August at 00:00 hrs and
#       the  'end'  file is touched 6 August at 00:00 hrs
touch 08010000 /tmp/start
touch 08060000 /tmp/end

# find files in /usr/tarquin directory
# newer than /tmp/a and not newer than /tmp/end
find  /usrs/tarquin  \(  -newer  /tmp/start  -a  !  -newer  /tmp/end
\) -print

rm -f /tmp/start /tmp/end

# That's the bare bones ...
# You will have to parse the dates if the user supplies them and ...
# you may want to tart it up a bit !

# --- SCRIPT END ----

Rob Quirk ( England )


>To anyone who is knowledgable in advanced unix cmds:

>I need to be able to do a find that prints out all of the files into a
>log file but the find must be able to find certain files that fall
>within a certain date range.  How do I do this? I checked the man
>pages out on find but there is no criteria that states a date range.
>I found one however that checks within the last x number of days
>(-mtime).    but that is not what I need.
>any help would be GREATLY appreciated !
>-LInda

 
 
 

using find cmd to locate files by date

Post by Linda Minni » Tue, 10 Aug 1999 04:00:00


Quote:>You simply have to convert the date range into the appropriate date offset.

...

This is what I was thinking of doing since I did find -mtime in the
man pages of find.  But thanks for clarifying this, I wasn't sure if
you could do an offset like you suggested! :)

Quote:

>find -mtime -9 -mtime +3

>Another thing you could do is convert your find command to Perl with
>find2perl, and then modify the resulting Perl script to do the date
>comparisons that you want.

I am actually doing this script in PERL now that you mention it.  I'm
a newbie at Perl programming, but in essence I'm trying to write a
perl CGI script that filters files from several directories into a
drop down menu.  One of these filters is by date.  Is there a way to
read just the date of a file into a string?  This may sound like a
complete waste of overhead but what I was doing was a
qx /ls -lrt/;  (to simulate the UNIX command) and then
reading that into a string. then,
I did a substr with an offset to pull out the date out of the string,
counting the characters to that point.  Am I completely wasting my
time doing so?
thanks for your help, I love you unix gurus!
 
 
 

using find cmd to locate files by date

Post by Linda Minni » Tue, 10 Aug 1999 04:00:00


On Mon, 9 Aug 1999 20:13:58 +0100, "RobertQuirk"

>I do not know of one command which will do this either but it isn't too hard
>to write a shell script ( after all unix is for programmers ! )

hehe I never programmed a unix shell script before, This unix cmd is
needed for a perl script.
nonetheless - I'm going to try this (your suggestion) anyhow !! I need
the practice and I love learning new things ;-)
Quote:

># --- SCRIPT START ---

>#!/bin/sh

># touch MMDDhhmm file
># eg. the 'start'  file is touched 1 August at 00:00 hrs and
>#       the  'end'  file is touched 6 August at 00:00 hrs
>touch 08010000 /tmp/start
>touch 08060000 /tmp/end

># find files in /usr/tarquin directory
># newer than /tmp/a and not newer than /tmp/end
>find  /usrs/tarquin  \(  -newer  /tmp/start  -a  !  -newer  /tmp/end
>\) -print

>rm -f /tmp/start /tmp/end

># That's the bare bones ...
># You will have to parse the dates if the user supplies them and ...
># you may want to tart it up a bit !

 
 
 

using find cmd to locate files by date

Post by Barry Margoli » Tue, 10 Aug 1999 04:00:00




>I am actually doing this script in PERL now that you mention it.  I'm
>a newbie at Perl programming, but in essence I'm trying to write a
>perl CGI script that filters files from several directories into a
>drop down menu.  One of these filters is by date.  Is there a way to
>read just the date of a file into a string?

Stat() will return the date as a numeric time, and you can use localtime()
to turn this into a date and time in numeric form.

--

GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

using find cmd to locate files by date

Post by John Gord » Tue, 10 Aug 1999 04:00:00



> To anyone who is knowledgable in advanced unix cmds:
> I need to be able to do a find that prints out all of the files into a
> log file but the find must be able to find certain files that fall
> within a certain date range.  How do I do this? I checked the man
> pages out on find but there is no criteria that states a date range.

create two sentinel files, with dates at each end of the date range you
are interested in.  (most versions of `touch' can create files with
arbitrary timestamps.)

run find, telling it to only report files that are newer than the old
sentinel file, and older than the new sentinel file.  (i.e. use the
-newer option twice, negating it for the second test.)

---
John Gordon                  "No Silicon Heaven?  Preposterous!  Where would

 
 
 

1. using locate to find files

I installed locate and it's companion files from the gcc find stuff.
however, it looks like that I'm not able to create the database.

somebody that could tell me how to use it ?

when updatedb is executed :

all options I tried with my (normally unlimited) fantasy doesn't
produce the
desired database. (not to mention that the man pages were a big help.
hmm..
not yet. the price I have to pay for using other operating platforms
and
other software...)

any help, anybody ?

2. Help, please? - Two ethernet, should forward with ip translation.

3. Korn shell date cmd - getting yesterday's date

4. Kernel Compilation Error

5. using date cmd

6. SIS based Ibm Aptiva : Invalid EIP

7. using "find" to grab files recursively by date

8. Netscape /w term

9. find files between date x and date y

10. bash: date of cmd in history file

11. find command to find files of a certain date

12. "find" command to find file on specific date?