GNU tar 1.34: B.1 Copying directory hierarchies
From Get docs
Tar/docs/latest/copy-directory-hierarchy
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
B.1 Copying directory hierarchies
This is a traditional way to copy a directory hierarchy preserving the dates, modes, owners and link-structure of all the files therein. It was used back when the cp
command lacked the ‘-a
’ option:
$ (cd sourcedir; tar -cf - .) | (cd targetdir; tar -xf -)
You can avoid subshells by using ‘-C
’ option:
$ tar -C sourcedir -cf - . | tar -C targetdir -xf -
The same command using long option forms:
$ (cd sourcedir; tar --create --file=- . ) \ | (cd targetdir; tar --extract --file=-)
or
$ tar --directory sourcedir --create --file=- . \ | tar --directory targetdir --extract --file=-
This document was generated on March 24, 2021 using texi2html 5.0.