1 1.1 christos #!/bin/sh 2 1.1 christos # Get modification time of a file or directory and pretty-print it. 3 1.1 christos # Copyright 1995, 1996, 1997 Free Software Foundation, Inc. 4 1.1 christos # written by Ulrich Drepper <drepper (at] gnu.ai.mit.edu>, June 1995 5 1.1 christos # 6 1.1 christos # This program is free software; you can redistribute it and/or modify 7 1.1 christos # it under the terms of the GNU General Public License as published by 8 1.1 christos # the Free Software Foundation; either version 2, or (at your option) 9 1.1 christos # any later version. 10 1.1 christos # 11 1.1 christos # This program is distributed in the hope that it will be useful, 12 1.1 christos # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 1.1 christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 1.1 christos # GNU General Public License for more details. 15 1.1 christos # 16 1.1 christos # You should have received a copy of the GNU General Public License 17 1.1 christos # along with this program; if not, write to the Free Software Foundation, 18 1.1 christos # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 1.1 christos 20 1.1 christos # As a special exception to the GNU General Public License, if you 21 1.1 christos # distribute this file as part of a program that contains a 22 1.1 christos # configuration script generated by Autoconf, you may include it under 23 1.1 christos # the same distribution terms that you use for the rest of that program. 24 1.1 christos 25 1.1 christos # Prevent date giving response in another language. 26 1.1 christos LANG=C 27 1.1 christos export LANG 28 1.1 christos LC_ALL=C 29 1.1 christos export LC_ALL 30 1.1 christos LC_TIME=C 31 1.1 christos export LC_TIME 32 1.1 christos 33 1.1 christos # Get the extended ls output of the file or directory. 34 1.1 christos # On HPUX /bin/sh, "set" interprets "-rw-r--r--" as options, so the "x" below. 35 1.1 christos if ls -L /dev/null 1>/dev/null 2>&1; then 36 1.1 christos set - x`ls -L -l -d $1` 37 1.1 christos else 38 1.1 christos set - x`ls -l -d $1` 39 1.1 christos fi 40 1.1 christos # The month is at least the fourth argument 41 1.1 christos # (3 shifts here, the next inside the loop). 42 1.1 christos shift 43 1.1 christos shift 44 1.1 christos shift 45 1.1 christos 46 1.1 christos # Find the month. Next argument is day, followed by the year or time. 47 1.1 christos month= 48 1.1 christos until test $month 49 1.1 christos do 50 1.1 christos shift 51 1.1 christos case $1 in 52 1.1 christos Jan) month=January; nummonth=1;; 53 1.1 christos Feb) month=February; nummonth=2;; 54 1.1 christos Mar) month=March; nummonth=3;; 55 1.1 christos Apr) month=April; nummonth=4;; 56 1.1 christos May) month=May; nummonth=5;; 57 1.1 christos Jun) month=June; nummonth=6;; 58 1.1 christos Jul) month=July; nummonth=7;; 59 1.1 christos Aug) month=August; nummonth=8;; 60 1.1 christos Sep) month=September; nummonth=9;; 61 1.1 christos Oct) month=October; nummonth=10;; 62 1.1 christos Nov) month=November; nummonth=11;; 63 1.1 christos Dec) month=December; nummonth=12;; 64 1.1 christos esac 65 1.1 christos done 66 1.1 christos 67 1.1 christos day=$2 68 1.1 christos 69 1.1 christos # Here we have to deal with the problem that the ls output gives either 70 1.1 christos # the time of day or the year. 71 1.1 christos case $3 in 72 1.1 christos *:*) set `date`; eval year=\$$# 73 1.1 christos case $2 in 74 1.1 christos Jan) nummonthtod=1;; 75 1.1 christos Feb) nummonthtod=2;; 76 1.1 christos Mar) nummonthtod=3;; 77 1.1 christos Apr) nummonthtod=4;; 78 1.1 christos May) nummonthtod=5;; 79 1.1 christos Jun) nummonthtod=6;; 80 1.1 christos Jul) nummonthtod=7;; 81 1.1 christos Aug) nummonthtod=8;; 82 1.1 christos Sep) nummonthtod=9;; 83 1.1 christos Oct) nummonthtod=10;; 84 1.1 christos Nov) nummonthtod=11;; 85 1.1 christos Dec) nummonthtod=12;; 86 1.1 christos esac 87 1.1 christos # For the first six month of the year the time notation can also 88 1.1 christos # be used for files modified in the last year. 89 1.1 christos if (expr $nummonth \> $nummonthtod) > /dev/null; 90 1.1 christos then 91 1.1 christos year=`expr $year - 1` 92 1.1 christos fi;; 93 1.1 christos *) year=$3;; 94 1.1 christos esac 95 1.1 christos 96 1.1 christos # The result. 97 1.1 christos echo $day $month $year 98