Finding Newer Files
Although
find
provides flags to locate files newer than certain days (-mtime -2), it is not fine grain enough to allow user to specify based on user-defined timestamp. Below script will touch
a temporary file with specific timestamp and find
will make use of it as a reference by using the "-newer" flag. FYI, this has been tested on Solaris
#! /bin/ksh if [ $# -ne 2 ]; then echo "Usage: $0 directory time" echo " time - a decimal number of the form: [[CC]YY]MMDDhhmm[.SS]" exit 1 fi directory=$1 timestamp=$2 if [ ! -d $directory ]; then echo "Error. Directory $directory does not exist" exit 2 fi tmpfile="/tmp/${0##*/}-$$" touch -t $timestamp $tmpfile > /dev/null 2>&1 if [ $? -ne 0 ]; then echo "Error. Incorrect time format [[CC]YY]MMDDhhmm[.SS]" exit 2 fi trap "rm -f $tmpfile; exit 0" EXIT find $directory -newer $tmpfile -local -mount -type f
Labels: shell script, Solaris
0 Comments:
Post a Comment
<< Home