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