[Seek Help] Linux系统中,如何简单有效的记录、查看文件的创建时间?
Tofloor
poster avatar
stainsun
deepin
2021-04-13 06:17
Author

如题,Linux中,如何简单有效的记录、查看文件的创建时间?

系统自带的三种时间,都不是创建时间:

atime 访问时间

mtime 修改时间

ctime 状态改变时间

网上很多说无法获取创建时间,不知道大家是怎么解决的。替代方法也可以,求告知。

Reply Favorite View the author
All Replies
zhangn1985
deepin
2021-04-13 07:16
#1

stat  1.7z 

  File: 1.7z

  Size: 18347419        Blocks: 35840      IO Block: 4096   regular file

Device: fc01h/64513d    Inode: 131102      Links: 1

Access: (0664/-rw-rw-r--)  Uid: (  500/  ubuntu)   Gid: (  500/  ubuntu)

Access: 2020-08-25 22:49:49.468507677 +0800

Modify: 2020-08-25 22:49:38.404508277 +0800

Change: 2020-08-25 22:49:38.404508277 +0800

 Birth: -

Reply View the author
zhangn1985
deepin
2021-04-13 07:18
#2

chmod a-w 1.7z 

ubuntu@VM-0-14-ubuntu:~$ stat  1.7z 

  File: 1.7z

  Size: 18347419        Blocks: 35840      IO Block: 4096   regular file

Device: fc01h/64513d    Inode: 131102      Links: 1

Access: (0444/-r--r--r--)  Uid: (  500/  ubuntu)   Gid: (  500/  ubuntu)

Access: 2020-08-25 22:49:49.468507677 +0800

Modify: 2020-08-25 22:49:38.404508277 +0800

Change: 2021-04-12 23:18:01.408250956 +0800

 Birth: -

Reply View the author
SamLukeYes
deepin
2021-04-13 07:22
#3

Reply View the author
SamLukeYes
deepin
2021-04-13 07:24
#4
zhangn1985

stat  1.7z 

  File: 1.7z

  Size: 18347419        Blocks: 35840      IO Block: 4096   regular file

Device: fc01h/64513d    Inode: 131102      Links: 1

Access: (0664/-rw-rw-r--)  Uid: (  500/  ubuntu)   Gid: (  500/  ubuntu)

Access: 2020-08-25 22:49:49.468507677 +0800

Modify: 2020-08-25 22:49:38.404508277 +0800

Change: 2020-08-25 22:49:38.404508277 +0800

 Birth: -

ext4 是可以记录创建时间的,你用的是啥文件系统啊

Reply View the author
wtz
deepin
2021-04-13 16:53
#5
SamLukeYes

ext4 是可以记录创建时间的,你用的是啥文件系统啊

ext4是支持的,但是旧版本的ls和stat不支持。你用的是新版coreutils,所以可以显示crtime。

参考:

https://unix.stackexchange.com/questions/50177/birth-is-empty-on-ext4

https://lkml.org/lkml/2010/7/22/249 (再次吐槽偏执狂Linus)

Reply View the author
SamLukeYes
deepin
2021-04-13 17:20
#6
wtz

ext4是支持的,但是旧版本的ls和stat不支持。你用的是新版coreutils,所以可以显示crtime。

参考:

https://unix.stackexchange.com/questions/50177/birth-is-empty-on-ext4

https://lkml.org/lkml/2010/7/22/249 (再次吐槽偏执狂Linus)

看来还是 Arch 大法好

Reply View the author
阿措
deepin
2021-04-13 18:53
#7

linux文件就这三种时间,创建文件的时候,mtime就是文件的创建时间,文件发生修改后,mtime会保存修改时间

Reply View the author
SamLukeYes
deepin
2021-04-13 19:08
#8
阿措

linux文件就这三种时间,创建文件的时候,mtime就是文件的创建时间,文件发生修改后,mtime会保存修改时间

其实和文件系统有关吧,ext4 就有 crtime

Reply View the author
阿措
deepin
2021-04-13 22:34
#9
SamLukeYes

其实和文件系统有关吧,ext4 就有 crtime

好吧,还没听说过这个实际创建时间

Reply View the author
stainsun
deepin
2021-04-14 06:19
#10
zhangn1985

chmod a-w 1.7z 

ubuntu@VM-0-14-ubuntu:~$ stat  1.7z 

  File: 1.7z

  Size: 18347419        Blocks: 35840      IO Block: 4096   regular file

Device: fc01h/64513d    Inode: 131102      Links: 1

Access: (0444/-r--r--r--)  Uid: (  500/  ubuntu)   Gid: (  500/  ubuntu)

Access: 2020-08-25 22:49:49.468507677 +0800

Modify: 2020-08-25 22:49:38.404508277 +0800

Change: 2021-04-12 23:18:01.408250956 +0800

 Birth: -

对,我也和你一样。birth是空,不显示。这几个命令都不起作用。

Reply View the author
stainsun
deepin
2021-04-14 06:22
#11
wtz

ext4是支持的,但是旧版本的ls和stat不支持。你用的是新版coreutils,所以可以显示crtime。

参考:

https://unix.stackexchange.com/questions/50177/birth-is-empty-on-ext4

https://lkml.org/lkml/2010/7/22/249 (再次吐槽偏执狂Linus)

多谢解答。我尝试了一下,可以查看:

原来是我的内核太旧了。这就更新。

Reply View the author
stainsun
deepin
2021-04-14 06:25
#12
SamLukeYes

是新内核的原因吗?直接stat就能看到创建时间,真方便。

我想一劳永逸,一个版本用很久,看来是不行,必须经常折腾才有新功能用。

Reply View the author
SamLukeYes
deepin
2021-04-14 06:40
#13
stainsun

是新内核的原因吗?直接stat就能看到创建时间,真方便。

我想一劳永逸,一个版本用很久,看来是不行,必须经常折腾才有新功能用。

如 5 楼所说,我的 coreutils 版本比较新,因为我用的是 Arch Linux

Reply View the author