简体   繁体   中英

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM