6

我使用 find 命令在 bash 中查找某些类型的文件。一切都很好,除非显示给我的结果只包含文件名,但不包含文件的(最后修改)日期。我试图将它通过管道传输到 ls 或 ls -ltr 但它只是没有在结果中显示 filedate 列,我也试过这个:

ls -ltr | find . -ctime 1

但实际上我没有工作。您能否指导我如何查看 find 命令返回的文件的文件日期?

4

3 回答 3

11

您需要xargs-exec为此:

find . -ctime 1 -exec ls -l {} \;

find . -ctime 1 | xargs ls -l

(第一个ls在每个找到的文件上单独执行,第二个将它们组合成一个或多个大ls调用,这样它们的格式可能会稍微好一些。)

于 2012-05-21T07:09:51.277 回答
7

如果您只想显示类似 ls 的输出,您可以使用-lsfind 选项:

$ find . -name resolv.conf -ls
1048592    8 -rw-r--r--   1 root     root          126 Dec  9 10:12 ./resolv.conf

如果您只想要时间戳,则需要查看该-printf选项

$ find . -name resolv.conf -printf "%a\n"
Mon May 21 09:15:24 2012
于 2012-05-21T07:15:51.153 回答
2
find . -ctime 1 -printf '%t\t%p\n'

打印日期时间和文件路径,以␉ 字符分隔。

于 2012-05-21T12:32:01.290 回答