LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Batch change timestamp/modification date data for multiple files? (https://www.linuxquestions.org/questions/linux-newbie-8/batch-change-timestamp-modification-date-data-for-multiple-files-4175690054/)

varaonaid 02-07-2021 06:12 AM

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. :)

rtmistler 02-07-2021 07:06 AM

Yes. Please review the --preserve option for the cp command.

lvm_ 02-07-2021 07:29 AM

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.

computersavvy 02-07-2021 12:58 PM

I believe rsync also preserves timestamps when using the -a option.

varaonaid 02-07-2021 10:24 PM

Quote:

Originally Posted by lvm_ (Post 6217343)
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.

rtmistler 02-08-2021 08:54 AM

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.

computersavvy 02-08-2021 12:11 PM

Quote:

Originally Posted by rtmistler (Post 6217786)
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.

computersavvy 02-08-2021 12:14 PM

Quote:

Originally Posted by lvm_ (Post 6217343)
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.

lvm_ 02-08-2021 12:41 PM

Quote:

Originally Posted by computersavvy (Post 6217887)
Please point me to a file manager that retains original timestamps when copying files.

mc - the daddy, dolphin.

JeremyBoden 02-08-2021 05:38 PM

That's a good reason not to use mc - or dolphin. :)

lvm_ 02-09-2021 05:57 AM

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.

JeremyBoden 02-09-2021 08:52 AM

I tried cp --preserve
It preserved the modification timestamp, but not the access, create or change timestamps [on a ext4 filesystem].

I don't see the point of --preserve...

nelz 02-09-2021 10:14 AM

rsync -a source/ dest/

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.)

chrism01 02-09-2021 08:58 PM

For cp you want --preserve=all.

For *nix files it's atime (access), mtime (content modified), ctime (meta data changed).
There is no 'create' time.

Exception: ext4 has/shows 'birth' time if you use the 'stat' cmd, BUT almost no tools set/read it, so you shouldn't rely on it.

computersavvy 02-10-2021 08:47 PM

Quote:

Originally Posted by chrism01 (Post 6218511)
For cp you want --preserve=all.

Even better, cp -a


All times are GMT -5. The time now is 07:09 AM.