bash 如何在bash中查看find命令结果的文件日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10680786/
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
How to view file date of result of find command in bash
提问by Farshid
I use a find command to find some kinds of files in bash. Everything goes fine unlness the result that is shown to me just contains the file name but not the (last modification) date of file. I tried to pipe it into ls or ls -ltr but it just does not show the filedate column in result, also I tried this:
我使用 find 命令在 bash 中查找某些类型的文件。一切都很好,除非显示给我的结果只包含文件名而不是文件的(最后修改)日期。我试图通过管道将它导入 ls 或 ls -ltr 但它只是没有在结果中显示文件日期列,我也试过这个:
ls -ltr | find . -ctime 1
but actually I didn't work. Can you please guide me how can I view the filedate of files returned by a find command?
但实际上我没有工作。你能指导我如何查看 find 命令返回的文件的文件日期吗?
回答by Kilian Foth
You need either xargsor -execfor this:
您需要xargs或-exec为此:
find . -ctime 1 -exec ls -l {} \;
find . -ctime 1 | xargs ls -l
(The first executes lson every found file individually, the second bunches them up into one ore more big lsinvocations, so that they may be formatted slightly better.)
(第一个ls单独对每个找到的文件执行,第二个将它们组合成一个或更多的大ls调用,以便它们的格式可以稍微好一些。)
回答by Bram
If all you want is to display an ls like output you can use the -lsoption of find:
如果您只想显示类似 ls 的输出,您可以使用-lsfind 选项:
$ find . -name resolv.conf -ls
1048592 8 -rw-r--r-- 1 root root 126 Dec 9 10:12 ./resolv.conf
If you want only the timestamp you'll need to look at the -printfoption
如果您只想要时间戳,则需要查看该-printf选项
$ find . -name resolv.conf -printf "%a\n"
Mon May 21 09:15:24 2012
回答by l0b0
find . -ctime 1 -printf '%t\t%p\n'
prints the datetime and file path, separated by a ? character.
打印日期时间和文件路径,以? 性格。

