user3653572
user3653572

Reputation: 25

Specific Linux find command

Hello all of you helpful folks!

I have been tasked with pulling down a list of the most recent files in our database. The problem is a simple find command will not work.

Our files are currently stored like in this format:

CLIENTNAME_20140522.xml --->> the second piece is today's day format.

I am having trouble with find because all of the files are listed by client name first and date.

Is there a way to look for the most recent file, by date?

Thank you in advance!

Upvotes: 0

Views: 57

Answers (1)

hek2mgl
hek2mgl

Reputation: 158010

In order to find the most recent file by the date in the pattern you can issue the following pipe:

find -regex '.*[0-9]+\.xml$' | sort -t_ -k2r | head -n1

Note, that there might be two files with the same date extension (from different clients). In this case it depends on find's output which of them will be selected.

Upvotes: 1

Related Questions