如何使用 Perl 在 Unix 中获取文件创建时间 [英] How to get file creation time in Unix with Perl

查看:44
本文介绍了如何使用 Perl 在 Unix 中获取文件创建时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 perl 在 unix 中获取文件创建时间?

How to get file creation time in unix with perl?

我有这个命令显示文件的最后修改时间:

I have this command which displays file's last modification time:

perl -MPOSIX -le 'print strftime "%d %b %Y %H:%M ".$_, localtime((lstat)[9]) for @ARGV' file.txt

推荐答案

在 UNIX 中通常没有文件创建时间.一个新的 xstat() 接口承诺支持它,但 perl 不使用它.可以编写一个基于 XS 的接口来访问它.

There is not normally file creation time in UNIX. A new xstat() interface promises support for it, but perl doesn't use it. It is possible to write an XS-based interface to gain access to it.

在 UNIX 上的 Perl 中,ctime 代表 Inode Change Time,与文件创建无关.

In Perl on UNIX, ctime stands for Inode Change Time, which has nothing to do with file creation.

根据perlportctime将仅在 Windows 上创建时间,但您可能想要使用 Win32API::File::Time::GetFileTime() 因为它更明确(并且对搬运工来说很明显)你的程序依赖于创建时间而不是 ctime 包含的任何内容.

According to perlport, ctime will be creation time only on Windows, but you might want to use the Win32API::File::Time::GetFileTime() since it is more explicit (and will be obvious to porters) that your program depends on creation time instead of whatever ctime contains.

这篇关于如何使用 Perl 在 Unix 中获取文件创建时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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