Using utimes
, futimes
, futimens
, etc., it is possible to set the access and modification timestamps on a file.
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.)
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.)
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?
For
ext2/3
and possibly forext4
you can do this withdebugfs
tool, assuming you want to change thectime
of file/tmp/foo
which resides in disk/dev/sda1
we want to set ctime to201001010101
which means 01 January 2010, time 01:01:Warning: Disk must be unmounted before this operation
Information taken from
Command Line Kung Fu
blog.The easiest way:
I tried this on windows 7 and I succeed to change all three timestamps. The stat command on linux shows that all three timestamps are changed.
I had a similar issue, and wrote my answer here.
https://stackoverflow.com/a/17066309/391040
There are essentially two options:
According to http://lists.gnu.org/archive/html/coreutils/2010-08/msg00010.html ctime cannot be faked (at least it's not intended to be fakeable):
If you just need to change a file's ctime for some testing/debugging, bindfs might be helpful. It's a FUSE filesystem which mounts one directory into another place, and can do some transformation on the file attributes. With option
--ctime-from-mtime
the ctime of each file is the same as its mtime, which you can set withtouch -t
.