Getting the most recent file

Hi people,

Please some help over here.

I have logs in a directory, in which I need to get the most recent file in order to put it within other command.

The format of the files are

loadfiles20090308094339_41
loadfiles20090308094418_42
loadfiles20090308095457_43
loadfiles20090310113306_46
loadfiles20090310132817_55
loadfiles20090310133103_56
loadfiles20090310133458_57
loadfiles20090316120301_36
loadfiles20090316122336_37
loadfiles20090316124025_38

The most recent file is always the last one in the list. After know the most recent file I need to use it with the command

more C:\data\loadfiles20090316124025_38\file.dat

Thanks in advance for any help.

Regards

Let's start with this -- BTW those are not unix filenames:

last=$( ls loadfile* -1 | tail -1)
more /data/${last}/file.dat

Hi jim,

It�s exactly what I need, many thanks.

A question:

What it means the part "-1 | tail -1"?

PD: They are windows file but I�lm processing with a Unix platform.:slight_smile:

ls -1 output one column of file names
tail -1 output the last record written from ls. tail -2 is the last two records, e.g.

Try this...

$ls -alt xxxx*.txt