Saturday, October 25, 2008

latest.sh

A bit lazy of me, but with my directories containing many entries, it's been easier to keep track of files via modification time. That's just what I've done with this script:

latest.sh

#!/bin/sh
FILE=
DATE=0
if [ $# -gt 0 ]; then
for i in "$@"
do
NDATE=`date -r "$i" '+%s'`
if [[ $NDATE -gt $DATE || -z "$FILE" ]]; then
FILE=$i
DATE=$NDATE
fi
done
echo "$FILE"
else
for i in *
do
NDATE=`date -r "$i" '+%s'`
if [[ $NDATE -gt $DATE || -z "$FILE" ]]; then
FILE=$i
DATE=$NDATE
fi
done
echo "$FILE"
fi

No comments: