bash 日期后的文件列表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5796719/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
List of files after a date
提问by Luke
I want to get all files after a specific date. I tried with:
我想在特定日期之后获取所有文件。我试过:
ls -ltr | awk {'print '} | sed s/-//g | awk {'if (-20110415 > 0 ) {print }'}
which works 50% fine. The last command prints only date of file. How to print date of file and filename? In the awk $8is the filename, but I don't know how to transfer till last printin the command line.
这工作 50% 罚款。最后一个命令只打印文件的日期。如何打印文件日期和文件名?在awk $8为文件名,但我不知道如何转移到最后print的命令行。
Thank you, Luke
谢谢你,卢克
回答by anubhava
回答by Konrad Kiss
If you are looking for a way to find updated files and process them, you could toucha file after your process ends and use find's -newer:
如果您正在寻找一种方法来查找更新的文件并处理它们,您可以touch在进程结束后创建一个文件并使用 find's -newer:
-newer file
File was modified more recently than file.
So when you need an updated files list, you'd want to do this:
因此,当您需要更新的文件列表时,您需要这样做:
find /path/to/dir -newer touched.file
find /path/to/dir -newer touched.file
This would recursively list all files in /path/to/dir that have a modification date that is later than that of touched.file. Don't forget to touch that touched.fileagain when you finish processing the updated files or make note of which file to test on your next iteration.
这将递归列出 /path/to/dir 中修改日期晚于touch.file 的所有文件。完成处理更新的文件后,不要忘记再次触摸该touched.file,或者记下在下一次迭代中要测试的文件。
回答by Dirjit
ls -ltr --time-style=long-iso <path> | awk '$6 >= "2018-10-10" {print $6,$8}'
ls -ltr --time-style=long-iso <path> | awk '$6 >= "2018-10-10" {print $6,$8}'
This gives me all files on the specified path that have been modified on 2018-10-10or later.
这为我提供了指定路径上已修改2018-10-10或稍后修改的所有文件。
--time-style=long-isois a good way of making sure the time includes the year, month and date. This helped me exclude old files if you keep multi year files.
--time-style=long-iso是确保时间包括年、月和日的好方法。如果您保留多年文件,这有助于我排除旧文件。
回答by Oct
What about this slightly modified version ?
这个稍微修改的版本怎么样?
ls -ltr | awk {'print " " '} | sed s/-//g | awk {'if (-20110426 > 0 ) {print " " }'}
Seems to do the trick for me... ?
似乎对我有用……?
回答by ZombieSheep
How about using findwith one of its various time-based switches, then using the printf to specify what fields you wish to display? You can find all the options in the man pages.
如何将find与其各种基于时间的开关之一结合使用,然后使用 printf 指定您希望显示的字段?您可以在手册页中找到所有选项。
EDIT- I'm not on a suitable environment to give you an example right now - I'll try to update the answer tomorrow
编辑- 我现在不在合适的环境中给你一个例子 - 我明天会尝试更新答案

