#!/bin/ksh # # $Id: lsd,v 1.4 2009/01/01 01:57:12 vogelke Exp $ # # list all of the files in a directory modified within # a given range of dates, or on just one specific date. # # relies on GNU versions of find and date. # # usage: lsd -s date [-e date] file [file...] # -s date: start (or only) date. # -e date: end date (optional); defaults to start plus 1 day. # # example: # me% lsd -s 'aug 10' -e 'aug 14' /tmp # -rw-r--r-- bin bin 41473 2007-08-10+23:59:04 /bkup/2007-08-10 # -rw-r--r-- bin bin 59073 2007-08-11+23:59:04 /bkup/2007-08-11 # -rw-r--r-- bin bin 1095227 2007-08-12+23:59:03 /bkup/2007-08-12 # -rw-r--r-- bin bin 48586 2007-08-13+23:59:04 /bkup/2007-08-13 # -rw-r--r-- bin bin 88148 2007-08-14+23:59:03 /bkup/2007-08-14 PATH=/bin:/usr/bin:/usr/local/bin:/opt/sfw/bin export PATH tag=`basename $0` # Return epoch equivalent of a day starting at midnight. midnight () { x=`gdate -d "$1" "+%Y/%m/%d"` rc=`gdate -d $x +%s` echo $rc } die () { echo "$tag: $*" >& 2 exit 1 } # Set the starting and ending dates. while getopts "e:s:" flag do case "$flag" in s) start=`midnight "$OPTARG"` ;; e) end=`midnight "$OPTARG"` ;; esac done case "$start" in "") start=`midnight today` ;; *) ;; esac case "$end" in "") end=$((start+86400)) ;; $start) end=$((start+86400)) ;; *) end=$((end+86400)) ;; # want the end of the day. esac test "$start" -le "$end" || die "dates out of order" case "$*" in "") set . ;; *) ;; esac # Print files plus mod times in epoch format, weed out # everything not between desired dates. This will mess # up if you have a tab embedded in a filename, but you # deserve that for putting tabs in filenames. shift $((OPTIND-1)) gfind $* -maxdepth 1 -printf "%T@\t%M\t%u\t%s\t%T+\t%p\n" | sort -n | awk ' BEGIN { FS = "\t" } $6 != "." { if ($1 >= '"$start"' && $1 <= '"$end"') printf "%s %8s %8d %s %s\n", $2,$3,$4,$5,$6 }' exit 0