Unix 中文件的所需格式的日期和时间

Date and time of a file in Unix in a desired format

谁能告诉我在 UNIX 中打印文件创建时间和日期的命令是什么?我在 Google 上搜索了很多并得到了 Linux 的解决方案。但是这些命令在 Sun OS.

上不起作用

Unix 没有文件创建时间。它有这些:

  • 最后修改时间(内容被修改)
  • 上次索引节点或文件状态更改时间(权限、链接数等属性已更改)
  • 上次访问时间(已阅读内容)
如果您不将输出提供给程序,

ls 是最佳选择。 man ls 是你的朋友。

ls -lu => show last access time
ls -lc => show last status change time
ls -l  => show last modified time (default)

一般来说,出于可移植性的考虑,不建议我们将 ls 的输出提供给程序。在 macOS 和 Linux 系统上,我们有一个 stat 命令来提取文件状态信息。


相关帖子:

Print a file's last modified date in Bash

How to get file creation time in Unix with Perl