Chris@82: #!/bin/sh Chris@82: # Get modification time of a file or directory and pretty-print it. Chris@82: Chris@82: scriptversion=2015-04-09.19; # UTC Chris@82: Chris@82: # Copyright (C) 1995-2014 Free Software Foundation, Inc. Chris@82: # written by Ulrich Drepper , June 1995 Chris@82: # Chris@82: # This program is free software; you can redistribute it and/or modify Chris@82: # it under the terms of the GNU General Public License as published by Chris@82: # the Free Software Foundation; either version 2, or (at your option) Chris@82: # any later version. Chris@82: # Chris@82: # This program is distributed in the hope that it will be useful, Chris@82: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@82: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@82: # GNU General Public License for more details. Chris@82: # Chris@82: # You should have received a copy of the GNU General Public License Chris@82: # along with this program. If not, see . Chris@82: Chris@82: # As a special exception to the GNU General Public License, if you Chris@82: # distribute this file as part of a program that contains a Chris@82: # configuration script generated by Autoconf, you may include it under Chris@82: # the same distribution terms that you use for the rest of that program. Chris@82: Chris@82: # This file is maintained in Automake, please report Chris@82: # bugs to or send patches to Chris@82: # . Chris@82: Chris@82: if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then Chris@82: emulate sh Chris@82: NULLCMD=: Chris@82: # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which Chris@82: # is contrary to our usage. Disable this feature. Chris@82: alias -g '${1+"$@"}'='"$@"' Chris@82: setopt NO_GLOB_SUBST Chris@82: fi Chris@82: Chris@82: case $1 in Chris@82: '') Chris@82: echo "$0: No file. Try '$0 --help' for more information." 1>&2 Chris@82: exit 1; Chris@82: ;; Chris@82: -h | --h*) Chris@82: cat <<\EOF Chris@82: Usage: mdate-sh [--help] [--version] FILE Chris@82: Chris@82: Pretty-print the modification day of FILE, in the format: Chris@82: 1 January 1970 Chris@82: Chris@82: Report bugs to . Chris@82: EOF Chris@82: exit $? Chris@82: ;; Chris@82: -v | --v*) Chris@82: echo "mdate-sh $scriptversion" Chris@82: exit $? Chris@82: ;; Chris@82: esac Chris@82: Chris@82: error () Chris@82: { Chris@82: echo "$0: $1" >&2 Chris@82: exit 1 Chris@82: } Chris@82: Chris@82: Chris@82: # Prevent date giving response in another language. Chris@82: LANG=C Chris@82: export LANG Chris@82: LC_ALL=C Chris@82: export LC_ALL Chris@82: LC_TIME=C Chris@82: export LC_TIME Chris@82: Chris@82: # Use UTC to get reproducible result Chris@82: TZ=UTC Chris@82: export TZ Chris@82: Chris@82: # GNU ls changes its time format in response to the TIME_STYLE Chris@82: # variable. Since we cannot assume 'unset' works, revert this Chris@82: # variable to its documented default. Chris@82: if test "${TIME_STYLE+set}" = set; then Chris@82: TIME_STYLE=posix-long-iso Chris@82: export TIME_STYLE Chris@82: fi Chris@82: Chris@82: save_arg1=$1 Chris@82: Chris@82: # Find out how to get the extended ls output of a file or directory. Chris@82: if ls -L /dev/null 1>/dev/null 2>&1; then Chris@82: ls_command='ls -L -l -d' Chris@82: else Chris@82: ls_command='ls -l -d' Chris@82: fi Chris@82: # Avoid user/group names that might have spaces, when possible. Chris@82: if ls -n /dev/null 1>/dev/null 2>&1; then Chris@82: ls_command="$ls_command -n" Chris@82: fi Chris@82: Chris@82: # A 'ls -l' line looks as follows on OS/2. Chris@82: # drwxrwx--- 0 Aug 11 2001 foo Chris@82: # This differs from Unix, which adds ownership information. Chris@82: # drwxrwx--- 2 root root 4096 Aug 11 2001 foo Chris@82: # Chris@82: # To find the date, we split the line on spaces and iterate on words Chris@82: # until we find a month. This cannot work with files whose owner is a Chris@82: # user named "Jan", or "Feb", etc. However, it's unlikely that '/' Chris@82: # will be owned by a user whose name is a month. So we first look at Chris@82: # the extended ls output of the root directory to decide how many Chris@82: # words should be skipped to get the date. Chris@82: Chris@82: # On HPUX /bin/sh, "set" interprets "-rw-r--r--" as options, so the "x" below. Chris@82: set x`$ls_command /` Chris@82: Chris@82: # Find which argument is the month. Chris@82: month= Chris@82: command= Chris@82: until test $month Chris@82: do Chris@82: test $# -gt 0 || error "failed parsing '$ls_command /' output" Chris@82: shift Chris@82: # Add another shift to the command. Chris@82: command="$command shift;" Chris@82: case $1 in Chris@82: Jan) month=January; nummonth=1;; Chris@82: Feb) month=February; nummonth=2;; Chris@82: Mar) month=March; nummonth=3;; Chris@82: Apr) month=April; nummonth=4;; Chris@82: May) month=May; nummonth=5;; Chris@82: Jun) month=June; nummonth=6;; Chris@82: Jul) month=July; nummonth=7;; Chris@82: Aug) month=August; nummonth=8;; Chris@82: Sep) month=September; nummonth=9;; Chris@82: Oct) month=October; nummonth=10;; Chris@82: Nov) month=November; nummonth=11;; Chris@82: Dec) month=December; nummonth=12;; Chris@82: esac Chris@82: done Chris@82: Chris@82: test -n "$month" || error "failed parsing '$ls_command /' output" Chris@82: Chris@82: # Get the extended ls output of the file or directory. Chris@82: set dummy x`eval "$ls_command \"\\\$save_arg1\""` Chris@82: Chris@82: # Remove all preceding arguments Chris@82: eval $command Chris@82: Chris@82: # Because of the dummy argument above, month is in $2. Chris@82: # Chris@82: # On a POSIX system, we should have Chris@82: # Chris@82: # $# = 5 Chris@82: # $1 = file size Chris@82: # $2 = month Chris@82: # $3 = day Chris@82: # $4 = year or time Chris@82: # $5 = filename Chris@82: # Chris@82: # On Darwin 7.7.0 and 7.6.0, we have Chris@82: # Chris@82: # $# = 4 Chris@82: # $1 = day Chris@82: # $2 = month Chris@82: # $3 = year or time Chris@82: # $4 = filename Chris@82: Chris@82: # Get the month. Chris@82: case $2 in Chris@82: Jan) month=January; nummonth=1;; Chris@82: Feb) month=February; nummonth=2;; Chris@82: Mar) month=March; nummonth=3;; Chris@82: Apr) month=April; nummonth=4;; Chris@82: May) month=May; nummonth=5;; Chris@82: Jun) month=June; nummonth=6;; Chris@82: Jul) month=July; nummonth=7;; Chris@82: Aug) month=August; nummonth=8;; Chris@82: Sep) month=September; nummonth=9;; Chris@82: Oct) month=October; nummonth=10;; Chris@82: Nov) month=November; nummonth=11;; Chris@82: Dec) month=December; nummonth=12;; Chris@82: esac Chris@82: Chris@82: case $3 in Chris@82: ???*) day=$1;; Chris@82: *) day=$3; shift;; Chris@82: esac Chris@82: Chris@82: # Here we have to deal with the problem that the ls output gives either Chris@82: # the time of day or the year. Chris@82: case $3 in Chris@82: *:*) set `date`; eval year=\$$# Chris@82: case $2 in Chris@82: Jan) nummonthtod=1;; Chris@82: Feb) nummonthtod=2;; Chris@82: Mar) nummonthtod=3;; Chris@82: Apr) nummonthtod=4;; Chris@82: May) nummonthtod=5;; Chris@82: Jun) nummonthtod=6;; Chris@82: Jul) nummonthtod=7;; Chris@82: Aug) nummonthtod=8;; Chris@82: Sep) nummonthtod=9;; Chris@82: Oct) nummonthtod=10;; Chris@82: Nov) nummonthtod=11;; Chris@82: Dec) nummonthtod=12;; Chris@82: esac Chris@82: # For the first six month of the year the time notation can also Chris@82: # be used for files modified in the last year. Chris@82: if (expr $nummonth \> $nummonthtod) > /dev/null; Chris@82: then Chris@82: year=`expr $year - 1` Chris@82: fi;; Chris@82: *) year=$3;; Chris@82: esac Chris@82: Chris@82: # The result. Chris@82: echo $day $month $year Chris@82: Chris@82: # Local Variables: Chris@82: # mode: shell-script Chris@82: # sh-indentation: 2 Chris@82: # eval: (add-hook 'write-file-hooks 'time-stamp) Chris@82: # time-stamp-start: "scriptversion=" Chris@82: # time-stamp-format: "%:y-%02m-%02d.%02H" Chris@82: # time-stamp-time-zone: "UTC" Chris@82: # time-stamp-end: "; # UTC" Chris@82: # End: