Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting creation or change timestamps

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?

like image 856
Thanatos Avatar asked Dec 27 '10 07:12

Thanatos


People also ask

How do you change the timestamp of a file?

If you want to change the last modified date or change the file creation data, press to enable the Modify date and time stamps checkbox. This will enable you to change the created, modified, and accessed timestamps—change these using the options provided.

What is timestamps of a file?

Timestamps are records for the times in which actions are performed on files. A timestamp is useful because it keeps records of when a file was accessed, modified, or added. Linux's files have 3 timestamps recorded by the computer: Access timestamp (atime): which indicates the last time a file was accessed.

How do you change a timestamp on a file in Linux?

The “-t” option modifies the time stamp of the file and the format is YYYYMMDDHHMM. The time stamp is changed to current system date and time after touch command is run with '-m' option.


1 Answers

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:

Warning: Disk must be unmounted before this operation

# 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 

Information taken from Command Line Kung Fu blog.

like image 139
ismail Avatar answered Sep 19 '22 06:09

ismail