How to preserve all timestamps while copying files
Red HatThis forum is for the discussion of Red Hat Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to preserve all timestamps while copying files
I need to copy a directory from one place to another. I want all the files, both in the source and the destination, to have the Access, Modify, and Change timestamps they had before I began the copy. I've found that cp, rsync, and tar each offer options that preserve some of the timestamps, but I can't find a way to preserve all of them. Doing a disk image copy is not an option. The directory has 3 million files spread out over tens of thousands of subdirectories going 20 levels deep, so anything that handles files individually is not practical. Does anyone know of a solution?
Doing a disk image copy is not an option. The directory has 3 million files spread out over tens of thousands of subdirectories going 20 levels deep, so anything that handles files individually is not practical.
So this is a separate issue. Your post seems more to be about just how to mirror data or something right? So, there are only a few layers in the storage stack to begin with, and you need to chose where you'll copy: block level? volume? filesystem? by file?
rsync -a sounds to do what you want.
If that looks like it'll be too slow, then I'd say just dd the source device to the target device. why is that not an option?
You can preserve the access and modify time, but not the change time, since whenever you copy a file a new inode is created.
OK - I guess I could live with that if that's the way it has to be. But it also changes the access timestamp at the destination. If I use cp -p, it won't change the access timestamp at the destination, but it changes it at the source. Seems like you just can't win.
But it also changes the access timestamp at the destination. If I use cp -p, it won't change the access timestamp at the destination, but it changes it at the source. Seems like you just can't win.
Just out of curiosity, why are you so concerned about change time? It is related to the inode and it is transparent to many commands, which on the contrary refer to the modification and/or the access time to work properly.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.