[P1] cp 101 question

Mike Wallinga mwallinga at mailup.net
Sat Jun 5 18:24:14 PDT 2004


Hi Scott,

As far as I can tell, the cp -R command will only recursively copy
subdirectories if your source argument is a directory itself.  In other
words, using *.doc as your source argument is what is causing the
problem.  But, if you only want the Word documents, you need to use that
pattern to match results somehow.

I'm no UNIX guru, so there might be a better way to do this.  But, if my
solution is any indication, your question certainly doesn't qualify as
"cp 101" caliber!  :-)  Here it is:

find . -name "*.doc" -exec cp {} /volumes/myfirewire  \;

The command assumes you're in the directory where you want to start your
search (that's what the period means).  When you find a file whose name
ends in .doc, the find command will execute the cp command, replace the
{} with the path and filename of the file it just found, and copy it to
/volumes/myfirewire.  The \; needs to be there to tell the -exec part
where the command to execute ends.

I did a simple test on my computer and this worked for me, but like I
said, I don't pretend to be a UNIX guru, so I may have missed something. 
Anyway, I hope this helps, or at least gets you on the right track to
accomplishing your goal!

- Mike W.



On Sat, 5 Jun 2004 16:27:33 -0500, "Scott Warren" <sw at shelton.org> said:
> I am wanting to back up just .doc files in all of their various 
> directories onto my firewire drive.  What is the Mac/Unix version of
> 	xcopy *.doc E:\backup -r
> 
> I have tried  cp -R *.doc \volumes\myfirewire    and this only copies 
> whats in the current directory and does not recurs the tree.
> 
> Tips??



More information about the iBook mailing list