[PLUG] Proper way to copy directories

Russell Senior seniorr at aracnet.com
Wed Dec 22 18:59:57 UTC 2004


>>>>> "Richard" == Richard C Steffens <rsteff.l at comcast.net> writes:

Richard> I'm finally getting around to moving /home over to the new
Richard> partition I created last week (or was it the week before?). I
Richard> read info coreutils cp, but got it wrong, so I'm looking for
Richard> the right way to move the files and preserve all the
Richard> attributes.

[...]

Richard> Or, is there another command I should be using?

I'd use either:

  rsync -v -a -H /home/ /home2/

or 

  tar -C /home -c . | tar -C /home2 -xpv

A few things to note:

  a) with this rsync command any files that were in /home2 before the
  command but that don't exist in /home will remain.  If you want an
  exact up-to-date copy of /home in /home2, you probably want to use
  the --delete option.

  b) the trailing slashes are significant in rsync.  I've forgotten
  exactly what the significance is, but the above example should
  work.  Read the man page for details.

  c) with the tar-to-tar, it is important *not* to include the verbose
  option on the first tar.  You are depending on standard input/output
  to move your data.  It is not likely to be pretty if you include the
  verbose information in that stream.

  d) there are many variations on the tar-to-tar technique.  If you
  have gnu tar at both ends, then this variant will work.

  e) both methods can work over a network through an ssh tunnel by
  appropriate modification, e.g.:

    rsync -e ssh -v -a -H /home/ hostname:/home2/

  or

    tar -C /home -c . | ssh hostname 'tar -C /home2 -xpv'


-- 
Russell Senior         ``I have nine fingers; you have ten.''
seniorr at aracnet.com



More information about the PLUG mailing list