[Gllug] Most Recent File

Peter Grandi pg_gllug at gllug.for.sabi.co.UK
Tue Nov 22 23:23:33 UTC 2005


>>> On Tue, 22 Nov 2005 15:24:01 +0000, Richard Jones <rich at annexia.org> said:

[ ... most ''recent'' file in a subtree ... ]

rich> My best attempt was:
rich>   ls -l --time-style='+%s' -R | sort -k6 | less
rich> but although it's just about human readable, it's not a
rich> very elegant solution, nor is it usable in scripts.

rich> I wonder if there's a better way without the attendant
rich> hideousness of find(1).

Well, if one can stomach 'find' a way to get (one of) the
''newest'' (or whatever 'test' can do) may be (hastily):

  find "$DIR" -type f -print \
  | (IT=''; while read THIS
     do test -z "$IT" -o "$THIS" -nt "$IT" && IT="$THIS"; done
     echo "$IT")

-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list