【问题标题】:Find all .py files across directory and subdirectories, fetch the last modified date of all and return the max date in a specific format跨目录和子目录查找所有 .py 文件,获取所有文件的最后修改日期并以特定格式返回最大日期
【发布时间】:2021-09-19 02:54:06
【问题描述】:

我一直在努力做到这一点。我的目录和子目录中有多个 .py 文件。我想找到并列出它们的日期和时间,并以"+%m-%d-%Y %H:%M:%S" 格式的变量返回最后更新的.py 文件的日期和时间。

我怎样才能做到这一点?

到目前为止,我只能在这个阶段访问它,它会显示终端中最后修改日期的统计信息。以下是我正在使用的命令:

find . -path ./ABC -prune -false -o -name '*.py' -exec ls -lat {} + | head -n1

这里我特别提到不要在./ABC文件夹中搜索。

上述命令的输出为:

-rw-rw----+ 1 owner server   8263 Jul  8 09:09 ./apps/Test.py

我正在寻找一种方法,可以在格式为 07-08-2021 09:09:30 的变量中返回上次更新文件(在本例中为 ./apps/Test.py)的日期和时间。

【问题讨论】:

标签: linux bash shell unix find


【解决方案1】:

只需find ... -printf。见man find。

find . -printf "%Tm-%Td-%TY %TH:%TM:%TS\t%p\n"

我看到find 输出打印带有小数部分的秒。您可以使用sed 过滤它们。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多