Copying directory trees, continued

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.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: