I wrote this find script for all those questions about 'files created in the last three hours' and 'files created more than 2 minutes ago'. This script *will* recurse into subdirectories.
As always, please suggest/make changes as you see fit.
#!/usr/bin/ksh
#set -x # unhash for debugging
print_help(){
echo "Usage: find.sh <num><h|m> dir_to_search_in <older|newer>"
echo "example:
find.sh 3m /tmp newer
this will search in /tmp for files created in the last 3 minutes.
find.sh 3h /tmp older
this will search in /tmp for files older than 3 hours."
}
PERLDIR=/opt/perl/bin # you can specify the path of your perl binary here
if [ $# -ne 3 ]; then
print_help
exit -2
fi
ARG1=$1
ARG2=$2
ARG3=$3
case "$ARG3" in
"newer") new_val="-newer";;
"older") new_val="! -newer";;
*) print_help; exit -2;;
esac
unit=`$PERLDIR/perl -w -e 'print chop $ARGV[0]' $ARG1`
diff=`$PERLDIR/perl -w -e 'print substr $ARGV[0],0,-1' $ARG1`
case $unit in
h) mult=3600;;
m) mult=60;;
*) print_help; echo "PLEASE NOTE: Only hour or minute granularity supported. For coarser stuff, use regular find. Finer granularity not yet supported."; exit -1;;
esac
diff_sec=$(($diff*$mult))
then_time=`$PERLDIR/perl -w -e '@mytime=localtime (time - $ARGV[0]); printf "%d%.2d%.2d%.2d%.2d", $mytime[5]+1900,$mytime[4]+1,$mytime[3],$mytime[2],$mytime[1];
' $diff_sec`
touch -m ${then_time} $ARG2/file_for_find
find $ARG2 -type f $new_val $ARG2/file_for_find
rm $ARG2/file_for_find
exit
--EDIT--
This has been tested on a HPUX 11.11 system. All utilities are HPUX standard.
--EDIT--