[X-Unix] copy 101 question

James Bucanek subscriber at gloaming.com
Sun Jun 6 07:48:31 PDT 2004


Stroller wrote on Sunday, June 6, 2004:
>I believe that you have tarred the files & then untarred them again in 
>order to preserve the directory-tree structure of the files, so that if 
>the user has ~/foo/some.doc and ~/foo/bar/some.doc then both files will 
>be copied to the destination drive and appropriate subdirectories made. 

Yes.

>I don't know if this is the default behaviour of xcopy, but believe 
>it's worth commenting on, because otherwise I'd regard this line as 
>more intuitive:
>     find Documents -name '*.doc' -exec cp \{\} /Volumes/firewire ;

I honestly don't remember how xcopy works (since I cut my teeth on UNIX, the DOS command line was so abhorrent to me, that I abandoned it at the first possible opportunity).  If, as I assumed, xcopy preserves the structure of the directories, then the tar trick works.  On the other hand, if it copies all of the source files into the same directory, then your command line is far more direct.  Furthermore, one could use ditto or CpMac in place of cp to copy the files properly, preserving any resource forks and any file meta-data.

>I can't see any shorter way than yours to preserve the directories when 
>copying found files, however. It seems to me a little inelegant to have 
>to use `tar` twice in this way

It's actually not that inelegant, nor is it particularly inefficient.  I like to think of most DOS and GUI utilities as Swiss Army knifes.  They are self-contained "do it all internally" monsters.  If you need recursion, there's a recursion option.

The philosophy in UNIX, in contrast, has always emulated the Erector Set.  You connect small tools together to create the solution that you want.  You don't have to relay on the author of some Rube Goldberg contraption to anticipate your solution.  So stringing together three or four "atoms" to make a molecule is "The UNIX Way."

>I would have expected a single command 
>to be available to do the the same thing, or a suitable flag to `cp`, 
>but I can't find either.

As I mentioned, I think the real solution is to find a resource-fork savvy synchronization or backup tool.  It's not like the file backup space hasn't been thoroughly explored.  ;)

______________________________________________________
James Bucanek       <mailto:privatereply at gloaming.com>



More information about the X-Unix mailing list