views:

721

answers:

3

Hi, Need to get the files between two given dates. If there are multiple files on one day get the latest of the files for that day.

A: 

I haven't tried it out, but there's a mailing list post about finding files between two dates. The relevant part:

Touch 2 files, start_date and stop_date, like this: $ touch -t 200603290000.00 start_date $ touch -t 200603290030.00 stop_date

Ok, start_date is 03/29/06 midnight, stop_date is 03/29/06 30 minutes after midnight. You might want to do a ls -al to check.

On to find, you can find -newer and then ! -newer, like this: $ find /dir -newer start_date ! -newer stop_date -print

Combine that with ls -l, you get: $ find /dir -newer start_date ! -newer stop_date -print0 | xargs -0 ls -l

(Or you can try -exec to execute ls -l. I am not sure of the format, so you have to muck around a little bit)

Mark Rushakoff
A: 

in bash shell, just an example, you can use the -nt test operator (korn shell comes with it also, if i am not wrong).

printf "Enter start date( YYYYMMDD ):"
read startdate
printf "Enter end date( YYYYMMDD ):"
read enddate
touch -t "${startdate}0000.00" sdummy
touch -t "${enddate}0000.00" edummy
for fi in *
do
    if [ $fi -nt "sdummy" -a ! $fi -nt "edummy" ] ;then
        echo "-->" $fi    
    fi
done
ghostdog74
A: 

What did you mean by two dates? Are the dates are part of the file name or you need to get the files based on their access time, creation time?

Sachin Chourasiya