zdate: add v and F options
This commit is contained in:
parent
058b3c2b00
commit
72416b2c1a
1 changed files with 26 additions and 19 deletions
45
zdate/zdate
45
zdate/zdate
|
|
@ -4,26 +4,25 @@ fname="$(basename "$0")"
|
||||||
|
|
||||||
usage()
|
usage()
|
||||||
{
|
{
|
||||||
echo "$fname [options] [path...]"
|
echo "$fname [options] [path...]
|
||||||
echo 'Display latest date of modification of any item in the path'
|
Display latest date of modification of any item in the path
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-v Invert, display oldest instead
|
||||||
|
-s Format to UNIX epoch
|
||||||
|
-F <format> Use the following date format. See 'man date'
|
||||||
|
"
|
||||||
}
|
}
|
||||||
|
|
||||||
while getopts ":hs" opt;
|
unset opt_s opt_v date_format
|
||||||
|
while getopts ":hsvF:" opt;
|
||||||
do
|
do
|
||||||
_opt=y
|
|
||||||
case $opt in
|
case $opt in
|
||||||
h)
|
h) usage ; exit 0 ;;
|
||||||
usage
|
s) opt_s=y ;;
|
||||||
exit 0
|
v) opt_v=y ;;
|
||||||
;;
|
F) date_format=$OPTARG ;;
|
||||||
s)
|
*) echo "Unknown option: $OPTARG" >&2 ; usage ; exit 1 ;;
|
||||||
_opt_s=y
|
|
||||||
;;
|
|
||||||
\?)
|
|
||||||
echo "Uknown option: $OPTARG" >&2
|
|
||||||
usage
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
@ -32,12 +31,20 @@ shift $((OPTIND-1))
|
||||||
targets="."
|
targets="."
|
||||||
[ $# -gt 0 ] && targets="$*"
|
[ $# -gt 0 ] && targets="$*"
|
||||||
|
|
||||||
ret=$(find $targets -printf '%T@\n' | sort -n | tail -n1 | cut -d'.' -f1)
|
if [ -n "$opt_v" ] ; then
|
||||||
|
ret=$(find $targets -printf '%T@\n' | sort -n | head -n1 | cut -d'.' -f1)
|
||||||
|
else
|
||||||
|
ret=$(find $targets -printf '%T@\n' | sort -n | tail -n1 | cut -d'.' -f1)
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -z "$_opt_s" ]
|
|
||||||
|
if [ -n "$opt_s" ]
|
||||||
then
|
then
|
||||||
|
true # do nothing: already in seconds
|
||||||
|
elif [ -n "$date_format" ] ; then
|
||||||
|
ret=$(date --date="$date_format" 2>/dev/null)
|
||||||
|
else # resolve to default date
|
||||||
ret=$(date --date="@$ret" 2>/dev/null)
|
ret=$(date --date="@$ret" 2>/dev/null)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[ -n "$ret" ] && echo $ret
|
[ -n "$ret" ] && echo $ret
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue