bash Unix - 文件创建日期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3127961/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 22:15:44  来源:igfitidea点击:

Unix - File Creation Date

bashshell

提问by helpermethod

For an assignment I need to determine the creation time of a random file. As far as I know, Unix does not store the creation time (in contrast to *-BSD). I think I've read somewhere that you should ask for the modification time instead but I don't know where and asking Google doesn't give me a non-ambigious answser either.

对于作业,我需要确定随机文件的创建时间。据我所知,Unix 不存储创建时间(与 *-BSD 相反)。我想我在某个地方读到过,你应该要求修改时间,但我不知道在哪里,问谷歌也不会给我一个明确的答案。

Any ideas?

有任何想法吗?

回答by Martin Wickman

You cannot get the creation time of files in this context. That makes the assignment easy enough: it reasonably cannot be completed.

在这种情况下,您无法获得文件的创建时间。这使得分配足够容易:它合理地无法完成。

If someone is talking about creation time in Unix, they are confused. Modification time is completely different from creation time (obviously).

如果有人在谈论 Unix 中的创建时间,他们会感到困惑。修改时间与创建时间完全不同(显然)。

For the record, there are exactly three timestamps in Unix files: ctime, atime and mtime.

作为记录,Unix 文件中正好有三个时间戳:ctime、atime 和 mtime

回答by Paused until further notice.

Try stat. It will give you all the times associated with a file.

试试stat。它将为您提供与文件相关的所有时间。

stat filename

To get just the modification date and time:

只获取修改日期和时间:

stat --format=%y filename

Or in seconds since the Epoch:

或者自纪元以来的几秒钟内:

stat --format=%Y filename