2 # Get modification time of a file or directory and pretty-print it.
3 # Copyright (C) 1995, 1996, 1997, 2003 Free Software Foundation, Inc.
4 # written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, June 1995
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software Foundation,
18 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 # As a special exception to the GNU General Public License, if you
21 # distribute this file as part of a program that contains a
22 # configuration script generated by Autoconf, you may include it under
23 # the same distribution terms that you use for the rest of that program.
25 # Prevent date giving response in another language.
35 # Find out how to get the extended ls output of a file or directory.
36 if ls -L /dev
/null
1>/dev
/null
2>&1; then
37 ls_command
='ls -L -l -d'
42 # A `ls -l' line looks as follows on OS/2.
43 # drwxrwx--- 0 Aug 11 2001 foo
44 # This differs from Unix, which adds ownership information.
45 # drwxrwx--- 2 root root 4096 Aug 11 2001 foo
47 # To find the date, we split the line on spaces and iterate on words
48 # until we find a month. This cannot work with files whose owner is a
49 # user named `Jan', or `Feb', etc. However, it's unlikely that `/'
50 # will be owned by a user whose name is a month. So we first look at
51 # the extended ls output of the root directory to decide how many
52 # words should be skipped to get the date.
54 # On HPUX /bin/sh, "set" interprets "-rw-r--r--" as options, so the "x" below.
55 set - x
`$ls_command /`
57 # Find which argument is the month.
63 # Add another shift to the command.
64 command="$command shift;"
66 Jan
) month
=January
; nummonth
=1;;
67 Feb
) month
=February
; nummonth
=2;;
68 Mar
) month
=March
; nummonth
=3;;
69 Apr
) month
=April
; nummonth
=4;;
70 May
) month
=May
; nummonth
=5;;
71 Jun
) month
=June
; nummonth
=6;;
72 Jul
) month
=July
; nummonth
=7;;
73 Aug
) month
=August
; nummonth
=8;;
74 Sep
) month
=September
; nummonth
=9;;
75 Oct
) month
=October
; nummonth
=10;;
76 Nov
) month
=November
; nummonth
=11;;
77 Dec
) month
=December
; nummonth
=12;;
81 # Get the extended ls output of the file or directory.
82 set - x
`eval "$ls_command \"\$save_arg1\""`
84 # Remove all preceding arguments
87 # Get the month. Next argument is day, followed by the year or time.
89 Jan
) month
=January
; nummonth
=1;;
90 Feb
) month
=February
; nummonth
=2;;
91 Mar
) month
=March
; nummonth
=3;;
92 Apr
) month
=April
; nummonth
=4;;
93 May
) month
=May
; nummonth
=5;;
94 Jun
) month
=June
; nummonth
=6;;
95 Jul
) month
=July
; nummonth
=7;;
96 Aug
) month
=August
; nummonth
=8;;
97 Sep
) month
=September
; nummonth
=9;;
98 Oct
) month
=October
; nummonth
=10;;
99 Nov
) month
=November
; nummonth
=11;;
100 Dec
) month
=December
; nummonth
=12;;
105 # Here we have to deal with the problem that the ls output gives either
106 # the time of day or the year.
108 *:*) set `date`; eval year
=\$
$#
119 Oct
) nummonthtod
=10;;
120 Nov
) nummonthtod
=11;;
121 Dec
) nummonthtod
=12;;
123 # For the first six month of the year the time notation can also
124 # be used for files modified in the last year.
125 if (expr $nummonth \
> $nummonthtod) > /dev
/null
;
127 year
=`expr $year - 1`
133 echo $day $month $year