Batch change timestamp/modification date data for multiple files?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
Batch change timestamp/modification date data for multiple files?
Hello,
I've copied several files from one drive to another by simply dragging and dropping. It didn't really hit me that this will give the files on the second drive a different timestamp/modification date. This isn't exactly a huge problem but it is when trying to make sure all files are present on both drives (when running a comparison) since it flags each timestamp/date difference as a different file.
I've read that one can copy the timestamp from one file to another but I can't seem to find any info on how to copy the timestamp/modified date to many files in a batch. Is this even possible or is it just a pipe dream?
If it's not possible and since I have far too many files to manually change one by one, is by best option simply coping the files again but this time, making sure to preserve the timestamp and mod date? Is there a way I can setup my file browser to preserve this data anytime I copy by dragging/dropping or is that simply not possible? Any help would be amazing! Thanks so much.
You may use 'touch -r file1 file2' to copy timestamp from file1 to file2. But it is a weird GUI shell you are using, proper ones should copy timestamps too. Most do.
You may use 'touch -r file1 file2' to copy timestamp from file1 to file2. But it is a weird GUI shell you are using, proper ones should copy timestamps too. Most do.
I'm using Nemo under XFCE. Is this not normal for it to behave that way? That's really interesting that you say the shell I'm using isn't working properly. I would have thought it should have moved the data/timestamps over.
I'll try moving some files with another GUI shell/file browser and see if I still have the issue. At least then I'd know if it's just Nemo giving me the issues.
I've always assumed that if I copied a file, the last modification date for it would be changed to the date and time when I now copied it. I honestly haven't paid much attention to defaults between the command line and various file managers, and instead retained my assumption whether it was valid or invalid. If it mattered, I'd perform a test and then review their documentation to determine if there was a way to alter that behavior. Ultimately I would probably revert to using the command line and specific switches provided for the command, so as to know for sure what to expect. Sorry, best I can offer, I cannot speak towards what your particular file manager does, and sorry I missed the detail that you were performing click/drag/copy versus a command line.
I've always assumed that if I copied a file, the last modification date for it would be changed to the date and time when I now copied it.
That is exactly how most file managers work, as does most cli copy tools unless you explicitly tell them to retain the original attributes. Ownership, time modified, and even selinux context can change when copying files. AFAIK only tar retains original attributes by default in the copy, but that is actually an archive tool so it is not the same.
However, if you tell the cli tool (such as cp or rsync) to treat this as an archive copy then all the original attributes are retained in the new copy.
You may use 'touch -r file1 file2' to copy timestamp from file1 to file2. But it is a weird GUI shell you are using, proper ones should copy timestamps too. Most do.
Please point me to a file manager that retains original timestamps when copying files. I know for a fact that nautilus and nemo do not.
That's not a clever thing to say even as a joke. By definition a copy is an exact duplicate of the original, not just the contents but metadata too - extended attributes, timestamps, etc. If it is not identical in any way, it means that the copy is flawed and creates issues like the one which started this thread, and the tool which was used to make this copy is flawed.
With the -a option, rsync syncs timestamps. As the contents of the files are the same, rsync won't try to copy those, so it should completely quickly, just resetting timestamps (and permissions etc.)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.