Find file by filename or with newest modified date

Hi,

I have a directory that has numerous files in it, and there is two which are named "filerec_ddmmyyHH24MMSS" by the time they are created so "filerec_010615012250" was created at 01:22:50 on 1st June 2015.

I need to find the most recently created of those 2 files and get the contents of it. Both files are created on the same day, so both will say for example 010615, but the hour, min, secs in the name will be different.

So i think i need to identify the file by finding the 'highest' HH24MMSS part of the file name. The alternative may be easier, just find which of the 2 files has the most recent modified date.

I haven't wrote any code at all yet, just trying to figure out how to identify the correct file first (I've tried a Find command with a printf but it doesnt seem to work)

Thanks

Check out

ls -ctl | head
1 Like

Look at the threads listed at the bottom of the page, e.g. Find the latest file based on the date in the filename.

1 Like
ls -tl | head -1

Take mtime (no -c) unless there is a good reason for ctime.

1 Like

Thanks all - much easier than i thought!
Cheers