简体   繁体   English

按时间戳递归过滤和排序文件

[英]Recursively filter & sort files by timestamp

I wanted to recursively search a directory for a particular file extension, and wanted the files to appear by timestamp (ie newest ones first).我想递归搜索特定文件扩展名的目录,并希望文件按时间戳出现(即最新的优先)。

Ideally, I'd want something like:理想情况下,我想要这样的东西:

ls -R -lth *.txt

but this doesn't work, although parts of it work:但这不起作用,尽管它的一部分起作用:

ls -lth *.txt
ls -R -lth

How do I need to modify my 'ls' command?我需要如何修改我的“ls”命令?

thanks!谢谢!

If you're using bash , you could enable the globstar shell option and use **/ to match zero or more subdirectories:如果您使用的是bash ,则可以启用globstar shell 选项并使用**/来匹配零个或多个子目录:

shopt -s globstar # enable globstar
ls -lth **/*.txt
shopt -u globstar # disable globstar

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

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