Copy files using tar

This is a oneliner to copy files from current directory to another target directory using tar, preserving file attributes, dates etc.

#!/bin/sh

fromdir=/path/from
todir=/path/to/target

echo "cd $fromdir; tar cf - . | (cd $todir; tar xpf -)"

cd $fromdir; tar cf - . | (cd $todir; tar xpf -)