9

How to change files CREATION time? I tried to use 'touch' command but it changes only the last modified time - it does not change the first date - creation date. (After checking by 'stat' it still shows me the original file creation date)

Is there any option to do this?

thanks in advance

wiwo
  • 199
  • 3
    Are you sure you mean the creation (aka birth) time? Few systems make that information available. Maybe you're thinking of the ctime (change time) – Stéphane Chazelas Jan 10 '17 at 13:25
  • 2
    touch newfile; cat oldfile > newfile; mv newfile oldfile – Shadur-don't-feed-the-AI Jan 10 '17 at 16:02
  • Creation time (crtime or btime/birth time) is different than ctime (change time) so that I vote for a re-open of this question that may not be a duplicate, if taken literally. I guess this is part is confusing "it does not change the first date - creation date", but we cannot know for sure, and the OP writes "CREATION", so... (and a recent enough stat does show creation time, even though, maybe not first). And if it IS/WAS a duplicate, it should have been edited for clarity before setting duplicate status IMHO. – Totor Apr 09 '22 at 12:17
  • Voting to leave closed - at the time OP posted this, stat on Linux certainly wasn't showing creation time. At the very least, this should be remain closed as unclear - OP needs to clarify which OS and filesystem this was before it should be reopened. – muru Apr 09 '22 at 16:02
  • The OP didn't mention linux. But the fact that OP never answered the comments hints that inode change time was mixed up with creation time. – Philippos Apr 11 '22 at 06:40
  • @Shadur, your solution is brilliant! Thank you! It should have been an answer, rather than a comment! Think I'll turn it into a bash function that overrides touch(1). The only thing lacking is that it won't work for multi-linked files. – Jan Steinman May 08 '22 at 05:40

3 Answers3

1

There is no way that creation time (btime) and change time(ctime) can be faked.

The only trick i could suggest you is to put back your system data, touch the file then get back "in the future".

0

You have to backup the file, delete it, then move the backup back in place, in order to modify the creation date in the inode.

Emeric
  • 863
-2

In linux, there is no creation time, there are only access, modify, and change dates. The POSIX standard only defines three distinct timestamps to be stored for each file: the time of last data access, the time of last data modification, and the time the file status last changed. Linux does not provide a kernel API for accessing the file creation times, even on filesystems supporting them (ext4, Btrfs and JFS), perhaps it will be impelemented in the future.

To modifie the accessed and modified time in a file, you can use the command touch with these options

-a = accessed
-m = modified
Dababi
  • 3,355
  • 24
  • 23
  • 4
    This is not actually true at all. https://superuser.com/a/703927/38062 https://unix.stackexchange.com/a/407305/5132 https://unix.stackexchange.com/q/24441/5132 – JdeBP May 18 '19 at 00:26