Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

copying directories



John Chambers wrote:
> 
> | cp -r -p <src> <dest>  to copy recursively and preserves file
> | attributes.
> 
> One thing missing from  this  is  that  novices  are  usually  rather
> surprised  and  disappointed  that,  if  <src>  is  a directory, this
> doesn't  make  <dest>  a  copy  of  <src>.   Rather,  it  creates   a
> subdirectory  of  <dest>  named  the same as <src> and puts the files
> there.  This is almost always not what was expected.  There has never
> been  a  simple  way  to  get  the unix cp command to simply copy one
> directory to another.
...
> The cleanest way to make <dest> into a copy of <src> is with a tar or
> cpio command.  For example:
> 
> 	tar cf - <src> | (cd <dest>; tar xpf -)
> or
> 	find <src> -print | cpio -pdum <dst>


Actually, I like to use the "rsync" command to do this; it solves the
problem as such (from the rsync man page):

              rsync -avz foo:src/bar /data/tmp

       this would recursively transfer all files from the  direc-
       tory  src/bar  on  the  machine foo into the /data/tmp/bar
       directory on the local machine. The files are  transferred
...
              rsync -avz foo:src/bar/ /data/tmp

       a  trailing  slash  on the source changes this behavior to
       transfer all files  from  the  directory  src/bar  on  the
       machine foo into the /data/tmp/.  A trailing / on a source
       name means "copy the contents of this directory".  Without
       a  trailing slash it means "copy the directory". This dif-


Note that you can use rsync to transfer files on the same host also; just
don't specify any other hosts.  So to copy the contents of src into dst:

	rsync -av src/ dst

--grg




BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org