Check out our Monthly Survey Page to see what our users are running.
Anyone know how to copy a folder, keeping the creation date of the original?
Page: «2/2
  Go to:
tuubi May 30, 2021
Quoting: denyasis
Quoting: Comandante ÑoñardoAnd If I play with the system time before making the copy?

That's a clever idea! Although, wouldn't you have to alter the system time for every file just before you copy it to ensure every file has the same time as the old? I wonder if that's is scriptable in bash?
Hah! I assume you would have to do exactly that. And of course it's scriptable. This is Linux!

The script shouldn't be too complicated either. I'd guess it would just iterate over the files, grab the file ctime (inode change time, not to be confused with data modification time) with something like `stat -L --printf='%Z' [FILE]`, set the system time with `date +%s -s @[TIMESTAMP]`, then copy the file over. Rinse and repeat. This is probably a bit slower than a straight copy, but you don't have to copy the whole folder in one go.

The resulting timestamps will differ just slightly from the originals, because there'll be a tiny delay between you setting the time and the subsequent copy operation creating the target file. It's also possible that this does not even work. I haven't tested any of the above, and I'm not going to.

Stat might also be able to return the actual file "birth time" if your coreutils package is recent enough and you use a file system that stores it. You can grab that into a variable with `stat -L --printf='%W'`. Most Linux software doesn't read or make any use of this timestamp though.

Note that messing with your system time will mess up timestamps for any processes writing logs or files at the same time, so you might want to use a live USB so your actual system is unaffected. Or something like that.

If you end up actually doing this, you've certainly got my respect for the dedication. I still don't see the point, but who cares. Tinkering is fun.

Last edited by tuubi on 30 May 2021 at 1:24 pm UTC
While you're here, please consider supporting GamingOnLinux on:

Reward Tiers: Patreon. Plain Donations: PayPal.

This ensures all of our main content remains totally free for everyone! Patreon supporters can also remove all adverts and sponsors! Supporting us helps bring good, fresh content. Without your continued support, we simply could not continue!

You can find even more ways to support us on this dedicated page any time. If you already are, thank you!
Login / Register


Or login with...
Sign in with Steam Sign in with Google
Social logins require cookies to stay logged in.

Buy Games
Buy games with our affiliate / partner links: