0

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

Velent
  • 39
  • @ilkkachu, even though POSIX might not support btimes, but some file systems supports it. And my goal is not to set source's btime to a target's, but to preserve target's existing one. So I'm really want to set anything back – Velent Sep 07 '23 at 05:57
  • @ilkkachu I need to preserve birth time. I don't care much about change time – Velent Sep 07 '23 at 06:05

1 Answers1

1

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.

Stephen Kitt
  • 434,908
  • wouldn't this do the same then: cat source >target? – FelixJN Sep 07 '23 at 07:09
  • Yes, it would; hence “one way of achieving” ;-). cp seems simpler to me and is more readily adapted to a variety of situations (for example, sudo cp source target rather than cat source | sudo tee target > /dev/null). – Stephen Kitt Sep 07 '23 at 07:13