简体   繁体   English

特定的Linux find命令

[英]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. 问题是简单的find命令将不起作用。

Our files are currently stored like in this format: 我们的文件当前以这种格式存储:

CLIENTNAME_20140522.xml --->> the second piece is today's day format. CLIENTNAME_20140522.xml --- >>第二部分是今天的格式。

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. 在这种情况下,取决于find的输出将选择其中的哪个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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