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. :) |
Yes. Please review the --preserve option for the cp command.
|
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 believe rsync also preserves timestamps when using the -a option.
|
Quote:
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.
|
Quote:
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. |
Quote:
|
Quote:
|
That's a good reason not to use mc - or dolphin. :)
|
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.
|
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... |
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.) |
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. |
Quote:
|
All times are GMT -5. The time now is 07:09 AM. |