Listing files bet. two specified dates

Brian Rice rice at dg-rtp.dg.com
Thu Oct 25 04:13:21 AEST 1990


In article <2162 at sixhub.UUCP>, davidsen at sixhub.UUCP (Wm E. Davidsen Jr) writes:
|> In article <9220005 at hpldsla.sid.hp.com> 
|> manoj at hpldsla.sid.hp.com (Manoj Joshi) writes:
|> | Alternatively, has anyone written a utility that will list out all
|> | files that have their modification times between two specified times.
|> | for eg., all files between Oct 1 1990  and  Oct 10 1990. 

The hardest part of this problem is the date arithmetic.  If the 
problem were to print all files modified between, say, 10 and 40 
days ago, the solution would be simple (I've tested this to some 
extent, but it's still more or less off the top of my head):

#!/bin/sh
# mbetween path bound_1 bound_2
# Argument 1 is taken to be the root of the directory tree to 
# search.  Argument 2 is one bound (in days), and argument 
# 3 is the other bound (in days).

find $1 -mtime -$2 -print > /tmp/mbetween.$$
find $1 -mtime -$3 -print >> /tmp/mbetween.$$

sort /tmp/mbetween.$$ > /tmp/mbetween2.$$
uniq -u /tmp/mbetween2.$$

rm -f /tmp/mbetween.$$ /tmp/mbetween2.$$
exit 0

If you had a date arithmetic package (didn't one just get posted
somewhere recently?) which supplied a Julian date function, you 
could provide a front end to mbetween (this is pseudocode):

#!/bin/sh
# better_mbetween path date_1 date_2

mbetween $1 `expr `jdate `date`` - `jdate $2`` \
            `expr `jdate `date`` - `jdate $3``
--
Brian Rice   rice at dg-rtp.dg.com   +1 919 248-6328
DG/UX Product Assurance Engineering
Data General Corp., Research Triangle Park, N.C.



More information about the Comp.unix.questions mailing list