OSX中目录的上次修改日期 [英] Last modified date of a directory in OSX

查看:85
本文介绍了OSX中目录的上次修改日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取终端中目录的最后修改日期?

How do I get the last modified date of a directory in terminal?

推荐答案

如果您只想获取修改日期(mtime),而没有其他内容

If you just want to get the modification date (mtime) and nothing else

stat --printf='%y\n' directory_name

或者,对于自该纪元以来的秒数:

or, for the date in seconds since the epoch:

stat --printf='%Y\n' directory_name

这比涉及ls/cut/grep/awk/find等的解决方案更直接,更有效,更强大

this is more straightforward, efficient and robust than solutions involving ls/cut/grep/awk/find etc

修改

上面是在OP在下面的评论中提到这是OSX之前发布的.

The above was posted before the OP mentioned that this was for OSX in the comments below.

OP使用stat/date达成了解决方案,我批准了该解决方案,因此将其添加到此处.

The OP arrived at a solution using stat/date, and I approve of the solution so I'm adding it here.

首先stat

stat -f "%m" /path/test.app

获取目录的mtime,然后将其包装为date以所需的格式获取

to get the directory's mtime, then wrap it in a date to get it in the required format

date -j -f "%s" "$(stat -f "%m" /path/test.app)" +"%Y/%m/%d %T"

这篇关于OSX中目录的上次修改日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆