LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 02-07-2021, 06:12 AM   #1
varaonaid
Member
 
Registered: Mar 2007
Posts: 50

Rep: Reputation: 2
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.
 
Old 02-07-2021, 07:06 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,877
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Yes. Please review the --preserve option for the cp command.
 
Old 02-07-2021, 07:29 AM   #3
lvm_
Member
 
Registered: Jul 2020
Posts: 884

Rep: Reputation: 308Reputation: 308Reputation: 308Reputation: 308
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.
 
Old 02-07-2021, 12:58 PM   #4
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,327

Rep: Reputation: 1481Reputation: 1481Reputation: 1481Reputation: 1481Reputation: 1481Reputation: 1481Reputation: 1481Reputation: 1481Reputation: 1481Reputation: 1481
I believe rsync also preserves timestamps when using the -a option.
 
Old 02-07-2021, 10:24 PM   #5
varaonaid
Member
 
Registered: Mar 2007
Posts: 50

Original Poster
Rep: Reputation: 2
Quote:
Originally Posted by lvm_ View Post
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.

Last edited by varaonaid; 02-07-2021 at 10:25 PM.
 
Old 02-08-2021, 08:54 AM   #6
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,877
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
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.
 
Old 02-08-2021, 12:11 PM   #7
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,327

Rep: Reputation: 1481Reputation: 1481Reputation: 1481Reputation: 1481Reputation: 1481Reputation: 1481Reputation: 1481Reputation: 1481Reputation: 1481Reputation: 1481
Quote:
Originally Posted by rtmistler View Post
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.
 
Old 02-08-2021, 12:14 PM   #8
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,327

Rep: Reputation: 1481Reputation: 1481Reputation: 1481Reputation: 1481Reputation: 1481Reputation: 1481Reputation: 1481Reputation: 1481Reputation: 1481Reputation: 1481
Quote:
Originally Posted by lvm_ View Post
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.
 
Old 02-08-2021, 12:41 PM   #9
lvm_
Member
 
Registered: Jul 2020
Posts: 884

Rep: Reputation: 308Reputation: 308Reputation: 308Reputation: 308
Quote:
Originally Posted by computersavvy View Post
Please point me to a file manager that retains original timestamps when copying files.
mc - the daddy, dolphin.
 
Old 02-08-2021, 05:38 PM   #10
JeremyBoden
Senior Member
 
Registered: Nov 2011
Location: London, UK
Distribution: Debian
Posts: 1,947

Rep: Reputation: 511Reputation: 511Reputation: 511Reputation: 511Reputation: 511Reputation: 511
That's a good reason not to use mc - or dolphin.
 
Old 02-09-2021, 05:57 AM   #11
lvm_
Member
 
Registered: Jul 2020
Posts: 884

Rep: Reputation: 308Reputation: 308Reputation: 308Reputation: 308
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.
 
1 members found this post helpful.
Old 02-09-2021, 08:52 AM   #12
JeremyBoden
Senior Member
 
Registered: Nov 2011
Location: London, UK
Distribution: Debian
Posts: 1,947

Rep: Reputation: 511Reputation: 511Reputation: 511Reputation: 511Reputation: 511Reputation: 511
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...
 
Old 02-09-2021, 10:14 AM   #13
nelz
Member
 
Registered: Aug 2004
Posts: 34

Rep: Reputation: 6
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.)
 
Old 02-09-2021, 08:58 PM   #14
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,348

Rep: Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749
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.
 
Old 02-10-2021, 08:47 PM   #15
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,327

Rep: Reputation: 1481Reputation: 1481Reputation: 1481Reputation: 1481Reputation: 1481Reputation: 1481Reputation: 1481Reputation: 1481Reputation: 1481Reputation: 1481
Quote:
Originally Posted by chrism01 View Post
For cp you want --preserve=all.
Even better, cp -a
 
  


Reply

Tags
batch, modification, timestamp


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
script to timestamp files with timestamp from directory eRJe Programming 4 11-13-2013 06:52 PM
copy all the files in the directory based on the modification date SriniKlr Programming 4 01-26-2011 10:08 AM
[SOLVED] copying files according to modification date and extension SriniKlr Linux - Newbie 5 01-03-2011 03:45 AM
[SOLVED] merge files by creation/modification date? andre.fm Linux - Newbie 5 10-04-2010 06:41 PM
copy folder/files according to modification date bkcreddy17 Programming 14 10-15-2008 07:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration