[wplug] Shell: 'find' trick

Brandon Kuczenski brandon at 301south.net
Sat Oct 15 14:56:41 EDT 2005


I have a series of files that all start with the same name prefix: 
something like `hostname -s`-fleem-`date +%F`.  The files were created on 
various irregular dates (i.e. not once per day or week, but once per 
whenever).

Can anyone think of a way to use 'find' to select only the newest file in 
a directory tree that starts with a given name?  I don't know when 
it was modified, only that it was modified more recently than the 
other files that match the pattern.  Example:

# ls
ocean-fleem-2005-10-01
ocean-fleem-2005-10-04
ocean-fleem-2005-10-05
ocean-fluum-2005-10-01
ocean-fluum-2005-10-04
ocean-fluum-2005-10-06
ocean-floob-2005-10-11
# find . -name "ocean-fleem*" -magic-commands-to-list-most-recent
./ocean-fleem-2005-10-05
#

Thanks in advance,
Brandon



More information about the wplug mailing list