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