【问题标题】:How to view file date of result of find command in bash如何在bash中查看find命令结果的文件日期
【发布时间】:2012-05-27 16:33:36
【问题描述】:

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

ls -ltr | find . -ctime 1

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

【问题讨论】:

    标签: bash find ls


    【解决方案1】:

    为此,您需要xargs-exec

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

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

    【讨论】:

    • 谢谢。完全正确。
    • @Farshid:-mtime是修改时间。
    【解决方案2】:

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

    $ 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
    

    【讨论】:

    【解决方案3】:
    find . -ctime 1 -printf '%t\t%p\n'
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-09
      • 1970-01-01
      • 1970-01-01
      • 2014-06-12
      • 1970-01-01
      • 2013-05-04
      • 1970-01-01
      • 2021-11-22
      相关资源
      最近更新 更多