linux取文件生成日期,如何在Linux中获取文件创建日期?

最近的近似“创建日期”是在struct stat的st_ctime成员,但实际上记录最后一次inode的改变。如果您创建该文件并且从不修改其大小或权限,那么该文件将用作创建时间。否则,至少在标准的Unix系统中,没有创建文件的时间记录。

出于您的目的,按st_mtime排序...或获取名称中带有时间戳的文件。

请注意,如果您是在达尔文(Mac OS X上),创建时间是可用的。从手册页stat(2):

然而,宏定义_DARWIN_FEATURE_64_BIT_INODE时,stat结构将现在被定义为:

struct stat { /* when _DARWIN_FEATURE_64_BIT_INODE is defined */

dev_t st_dev; /* ID of device containing file */

mode_t st_mode; /* Mode of file (see below) */

nlink_t st_nlink; /* Number of hard links */

ino_t st_ino; /* File serial number */

uid_t st_uid; /* User ID of the file */

gid_t st_gid; /* Group ID of the file */

dev_t st_rdev; /* Device ID */

struct timespec st_atimespec; /* time of last access */

struct timespec st_mtimespec; /* time of last data modification */

struct timespec st_ctimespec; /* time of last status change */

struct timespec st_birthtimespec; /* time of file creation(birth) */

off_t st_size; /* file size, in bytes */

blkcnt_t st_blocks; /* blocks allocated for file */

blksize_t st_blksize; /* optimal blocksize for I/O */

uint32_t st_flags; /* user defined flags for file */

uint32_t st_gen; /* file generation number */

int32_t st_lspare; /* RESERVED: DO NOT USE! */

int64_t st_qspare[2]; /* RESERVED: DO NOT USE! */

};

注意st_birthtimespec领域。请注意,所有时间都在struct timespec值中,因此存在亚秒时间(tv_nsec给出纳秒分辨率)。 POSIX 2008 要求struct timespec时间保持在标准时间;达尔文遵循这一点。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值