mdate-sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/sh
  2. # Get modification time of a file or directory and pretty-print it.
  3. # Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
  4. # written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, June 1995
  5. #
  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)
  9. # any later version.
  10. #
  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.
  15. #
  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.
  19. # Prevent date giving response in another language.
  20. LANG=C
  21. export LANG
  22. LC_ALL=C
  23. export LC_ALL
  24. LC_TIME=C
  25. export LC_TIME
  26. # Get the extended ls output of the file or directory.
  27. # On HPUX /bin/sh, "set" interprets "-rw-r--r--" as options, so the "x" below.
  28. if ls -L /dev/null 1>/dev/null 2>&1; then
  29. set - x`ls -L -l -d $1`
  30. else
  31. set - x`ls -l -d $1`
  32. fi
  33. # The month is at least the fourth argument
  34. # (3 shifts here, the next inside the loop).
  35. shift
  36. shift
  37. shift
  38. # Find the month. Next argument is day, followed by the year or time.
  39. month=
  40. until test $month
  41. do
  42. shift
  43. case $1 in
  44. Jan) month=January; nummonth=1;;
  45. Feb) month=February; nummonth=2;;
  46. Mar) month=March; nummonth=3;;
  47. Apr) month=April; nummonth=4;;
  48. May) month=May; nummonth=5;;
  49. Jun) month=June; nummonth=6;;
  50. Jul) month=July; nummonth=7;;
  51. Aug) month=August; nummonth=8;;
  52. Sep) month=September; nummonth=9;;
  53. Oct) month=October; nummonth=10;;
  54. Nov) month=November; nummonth=11;;
  55. Dec) month=December; nummonth=12;;
  56. esac
  57. done
  58. day=$2
  59. # Here we have to deal with the problem that the ls output gives either
  60. # the time of day or the year.
  61. case $3 in
  62. *:*) set `date`; eval year=\$$#
  63. case $2 in
  64. Jan) nummonthtod=1;;
  65. Feb) nummonthtod=2;;
  66. Mar) nummonthtod=3;;
  67. Apr) nummonthtod=4;;
  68. May) nummonthtod=5;;
  69. Jun) nummonthtod=6;;
  70. Jul) nummonthtod=7;;
  71. Aug) nummonthtod=8;;
  72. Sep) nummonthtod=9;;
  73. Oct) nummonthtod=10;;
  74. Nov) nummonthtod=11;;
  75. Dec) nummonthtod=12;;
  76. esac
  77. # For the first six month of the year the time notation can also
  78. # be used for files modified in the last year.
  79. if (expr $nummonth \> $nummonthtod) > /dev/null;
  80. then
  81. year=`expr $year - 1`
  82. fi;;
  83. *) year=$3;;
  84. esac
  85. # The result.
  86. echo $day $month $year