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