设置创建或更改时间戳 [英] Setting creation or change timestamps
问题描述
使用utimes
,futimes
,futimens
等,可以设置文件的访问和修改时间戳.
Using utimes
, futimes
, futimens
, etc., it is possible to set the access and modification timestamps on a file.
修改时间是文件数据上一次更改的时间.同样,"ctime"或更改时间是文件上的属性(例如权限)的最后一次更改. (Linux/POSIX维护了三个时间戳:已经讨论过的mtime和ctime以及"atime"或访问时间.)
Modification time is the last time the file data changed. Similarly, "ctime" or change time, is the last time attributes on the file, such as permissions, were changed. (Linux/POSIX maintains three timestamps: mtime and ctime, already discussed, and 'atime', or access time.)
有设置变更时间戳记的功能吗? (其中更改"是属性修改或"ctime",不是修改时间"mtime".)(我了解想要更改更改时间戳的周期性,但是认为存档软件会-非常好地恢复原样.)
Is there a function to set change timestamps? (Where "change" is the attribute modification or 'ctime', not modification time 'mtime'.) (I understand the cyclic nature of wanting to change the change timestamp, but think archiving software - it would be nice to restore a file exactly as it was.)
创建时间戳有任何功能吗? (我意识到ext2
不支持此功能,但是我想知道Linux是否支持那些支持它的文件系统.)
Are there any functions at all for creation timestamps? (I realize that ext2
does not support this, but I was wondering if Linux did, for those filesystems that do support it.)
如果不可能,那么背后的原因是什么?
If it's not possible, what is the reasoning behind it not being so?
推荐答案
对于ext2/3
,可能还有ext4
,您可以使用debugfs
工具进行此操作,假设您想更改文件/tmp/foo
的ctime
>驻留在磁盘/dev/sda1
中,我们要将ctime设置为201001010101
,这意味着2010年1月1日,时间01:01:
For ext2/3
and possibly for ext4
you can do this with debugfs
tool, assuming you want to change the ctime
of file /tmp/foo
which resides in disk /dev/sda1
we want to set ctime to 201001010101
which means 01 January 2010, time 01:01:
警告:此操作之前必须先卸载磁盘
# Update ctime
debugfs -w -R 'set_inode_field /tmp/foo ctime 201001010101' /dev/sda1
# Drop vm cache so ctime update is reflected
echo 2 > /proc/sys/vm/drop_caches
信息取自 Command Line Kung Fu
博客.
Information taken from Command Line Kung Fu
blog.
这篇关于设置创建或更改时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!