how to compare file modification time (whole dir tree?)

Liam R. E. Quin lee at sq.sq.com
Sat Aug 4 01:56:51 AEST 1990


fritz at mercury.caltech.edu (Fritz Nordby) writes:
> Am I missing something here, or will the following [work]?
>
>#!/bin/sh
>case $# in 2);;*)echo "usage: ${0:-newer} file1 file2" >&2;exit 2;;esac
>[ ! -f "$2" -o -f "$1" -a "X`/bin/ls -t \"\$1\" \"\$2\"`" = "X$1
>$2"] >/dev/null 2>&1

I have no idea.  It *might* have won the Obfuscated Shell Contest, except
that there isn't one.  At first I thought it was a perl script.
I have had a go at expanding this a little below... although I'd probably
use find(1) instead for this.  [I mised the original article, presumably
there was some reason not to use find apart from ``I don't understand it'']

Lee


#! /bin/sh

# valilidate arguments:
case $# in
2)  ;;
*)  echo "usage: ${0:-newer} file1 file2" >&2
    exit 2
    ;;
esac

if [ ! -f "$2" -o ! -f "$1" ]
then
    # we might want to print an error message here??
    exit 1
fi

LsOuput=`/bin/ls -dt "$1" "$2"`
FirstNewer="$1
$2"

test x"${LsOutput}" = x"${FirstNewer}

exit $?

-- 
Liam R. E. Quin,  lee at sq.com, {utai,utzoo}!sq!lee,  SoftQuad Inc., Toronto
``He left her a copy of his calculations [...]  Since she was a cystologist,
  she might have analysed the equations, but at the moment she was occupied
  with knitting a bootee.''  [John Boyd, Pollinators of Eden, 217]



More information about the Alt.sources.d mailing list