How to preserve file creation date when overwriting files?

When I’m overwriting one file with another one, not only it’s modification time updates, but also birth time, which is unwanted.
I want to make Dolphin overwrite files that way, so target’s birth time will stay the same the same as it was before overwriting.

But, if it’s impossible to configure Dolphin that way, any other method will be appreciated.

Debian 12

Asked By: Velent


Birth time can’t be set arbitrarily, other than by setting the “context” time (system time typically). This means that it isn’t possible to copy a file to another and have the copy preserve the original’s birth time. (See Why does this use of `cp -a` not preserve creation time? for details.)

It is however possible to preserve an existing target’s birth time (and I get the impression that’s what you’re after). To do so, the copy operation has to ensure that the target isn’t replaced entirely, only its contents; more explicitly, instead of deleting the existing target and creating a new file for the copy, the existing target should be emptied (truncated) and the source data copied to it. This is how cp is supposed to operate, unless an error prevents it from truncating or writing to the existing target.

So one way of achieving your goal is to use plain old cp to copy your files. You should also ensure, before starting the copy operation, that all the existing target files are writable.

Answered By: Stephen Kitt