Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I'm interested in combining the files from three Macs by copying the files from each one into a single folder hierarchy of my design on an external hard drive.

In my past experience copying files in OSX, sometimes the files lose their Created and Modified timestamps; i.e. they are changed to the present moment when the file copy happens.

How can I make sure this doesn't happen?

share|improve this question
    
When do you lose timestamps? –  lhf Jan 31 '13 at 11:06
    
Copying them how? –  Gerry Jan 31 '13 at 11:20

4 Answers 4

I use rsync to do this sort of copy

for example

rsync -aE source_dir target_dir

The option -E copies the ACLs and -a preserves the unix permissions and times.

rsync can also be setup to copy to remote machines without mounting drives.

There are some GUI front ends for rsync e.g. aRsync. For other directory synchronization tools see this question.

share|improve this answer
    
rsync is a good solution, but be aware that it doesn't preserve access times. pax (see my answer below) does. –  jaume Feb 18 '13 at 10:26
    
As far as I know, "rsync" forgets the creation date and instead sets it to the modif date. Which is a big failure. –  Nicolas Barbulesco Sep 3 at 9:20
    
→ jaume: any command making any form of copy of "file a" toward "file b" has to read "file a" first. Hence the access time of "file a" should be modified. This isn't a feature at the command level but at the kernel level. If a command, through another system call, restores the access time to its previous state, then this is a dangerous trick, because it is a plain lie. –  daniel Azuelos Sep 3 at 10:15
    
→ Nicolas: cf. man rsync and search for preserve times :) ⇒ the answer from Mark is correct. –  daniel Azuelos Sep 3 at 10:18
    
@daniel - This article says otherwise : Do You Copy? Especially, see the table at the end. –  Nicolas Barbulesco Sep 3 at 11:49

I just ran across this myself, and the built in cp command actually handles it.

I discovered a bunch of old CF cards that I wanted to harvest the pictures from. My processing scripts will look at the file mtime to put it in the correct place so I needed it preserved.

From the man page:

 -p    Cause cp to preserve the following attributes of each source file in the copy: modification time,
       access time, file flags, file mode, user ID, and group ID, as allowed by permissions.  Access
       Control Lists (ACLs) and Extended Attributes (EAs), including resource forks, will also be pre-
       served.

       If the user ID and group ID cannot be preserved, no error message is displayed and the exit value
       is not altered.

       If the source file has its set-user-ID bit on and the user ID cannot be preserved, the set-user-
       ID bit is not preserved in the copy's permissions.  If the source file has its set-group-ID bit
       on and the group ID cannot be preserved, the set-group-ID bit is not preserved in the copy's per-
       missions.  If the source file has both its set-user-ID and set-group-ID bits on, and either the
       user ID or group ID cannot be preserved, neither the set-user-ID nor set-group-ID bits are pre-
       served in the copy's permissions.

So, using zsh I was able to run (NO NAME being my cards volume name):

cp -rvp /Volumes/NO\ NAME/DCIM/**/*.{JPG,jpg} ~/Desktop/tmp/pics

I believe that the special /**/* construct is specific to ZSH; however you could do something like

find /Volumes/WHATEVER -type d -print0 | xargs cp -vp {}/*.JPG /my/out/path
share|improve this answer
    
+1 A simple cp -p is straight-forward, preserves the modified time (likely the most useful of the three timestamps on a file) and doesn't require creation of an intermediate archive file. –  wberry Jan 28 at 19:57
    
As far as I know, "cp -p" forgets the creation date and instead sets it to the modif date. Which is quite an absurd behaviour. –  Nicolas Barbulesco Sep 3 at 9:19

Use pax. The default pax format, called ustar, preserves file modification and access times (among other things like user ID, group ID, file mode bits and extended attributes like Spotlight comments and ACLs). See pax man page here for more details.

First, create a pax archive on every Mac and copy it to the external hard drive like this:

  1. Open Applications>Utilities>Terminal.
  2. Type in Terminal:

    $ cd
    

    and drag the folder where the files to be combined reside on that Mac to Terminal:

    enter image description here

    Alternatively you can type the full folder name:

    $ cd /path/to/your\ folder
    

    This will change the current folder to 'your folder'.

  3. Archive the folder with pax:

    $ cd ..
    $ pax -w "your folder" > yourfolder.ustar
    
  4. Use the Finder to copy the newly create archive yourfolder.ustar to the external hard drive.

Then extract the archives with pax:

  1. Open Terminal on the Mac that has the external USB hard drive plugged in.

  2. Change the current folder to the single folder hierarchy on the external hard drive with command cd as explained above:

    $ cd /Volumes/externalHDD/path/to/single \folder
    $ ls
    yourfolder.ustar
    yourfolder2.ustar
    yourfolder3.ustar
    
  3. Extract the archives:

    $ pax -r -p e < yourfolder.ustar
    $ pax -r -p e < yourfolder2.ustar
    $ pax -r -p e < yourfolder3.ustar
    $ ls
    your folder
    your folder 2
    your folder 3
    
  4. Move the files around with the Finder if you need to (the Finder preserves file modification and access times within the same volume).

(I've tested this procedure on OS X 10.8 (Mountain Lion).)

share|improve this answer

Compress them with zip or select them with ctrl-click or right-click and choose Compress. Copy the compressed files to your target system and open them there.

If you can, format your external drive as a Mac OS filesystem, not FAT.

share|improve this answer
    
Not Option-click. Ctrl-click. Or right-click. –  Nicolas Barbulesco Sep 3 at 9:25
    
The best choice for formatting the disk is Mac OS Extended Journalled. Mac OS Extended is also called HFS+. –  Nicolas Barbulesco Sep 3 at 9:27
1  
@NicolasBarbulesco, fixed, thanks. –  lhf Sep 3 at 10:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.