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

2
  • @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 Commented Sep 7, 2023 at 5:57
  • @ilkkachu I need to preserve birth time. I don't care much about change time Commented Sep 7, 2023 at 6:05

1 Answer 1

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.

2
  • wouldn't this do the same then: cat source >target? Commented Sep 7, 2023 at 7: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). Commented Sep 7, 2023 at 7:13

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.