tar -cvf - `find ./srcdir -type d` | (cd ./destdir ; tar -xvf - )
but this version is giving error to me:
cd ./srcdir &&
tar -cf - . |
gzip -9 |
cd ../destdir &&
gzip -d |
tar -xf -
error is: gzip: compressed data not read from a terminal. Use -f to force decompression.
For help, type: gzip -h
tar: This does not look like a tar archive
tar: Error exit delayed from previous errors
gzip is not receiving the input from the pipeline, it is lost by the cd. However some versions of cd will allow you to do something like tar cf - | cd target | tar xf -, or use a subshell (put parentheses around the cd; gzip -d | tar xf -)
Some versions of tar also have an option to switch directories when starting; with GNU tar, this is tar -C directory