tar: copy directory hierarchy

1 
1 B.1 Copying directory hierarchies
1 =================================
1 
1 This is a traditional way to copy a directory hierarchy preserving the
1 dates, modes, owners and link-structure of all the files therein.  It
1 was used back when the 'cp' command lacked the '-a' option:
1 
1      $ (cd sourcedir; tar -cf - .) | (cd targetdir; tar -xf -)
1 
1 You can avoid subshells by using '-C' option:
1 
1      $ tar -C sourcedir -cf - . | tar -C targetdir -xf -
1 
1 The same command using long option forms:
1 
1      $ (cd sourcedir; tar --create --file=- . ) \
1             | (cd targetdir; tar --extract --file=-)
1 
1 or
1 
1      $ tar --directory sourcedir --create --file=- . \
1             | tar --directory targetdir --extract --file=-
1