By blogfinger on Nov 02, 2009
As mentioned earlier, I am using rsync to copy complete directory trees:
$ cd /source_dir $ rsync -avz . /dest_dir
It will copy all files, including hidden ones, in directory /source_dir, into the destination directory /dest_dir. In case /dest_dir does not already exist, rsync will create it (at least on my Nevada 72 system).
There may be cases where rsync does not work correctly, for example when there are very long file names. Good to know that there's another easy way to do it:
$ cd /source_dir $ find . -print -depth | cpio -pdm /dest_dir
The -depth parameter makes find print file names first, and -pdm with cpio means (from man cpio):
-p: reads a list of file path names from stdio and copies those files to the destination tree.
-d: creates directories if necessary
-m: keep file modification times
Destination directory /dest_dir must exist before starting the above commands.