Saturday, 29 December 2007

Copying whole partitions preserving hidden files and attributes

How do you easily and coherently copy a whole large and complex directory, preserving attribution, hidden files etc? Good old cp -a could not be enough in this case (hidden files would be skipped), and maybe you don't want to use dd (e.g. you could like to move a ReiserFS partition to an ext3 partition). The trick is hidden in the Debian tips , but can be applied to any Linux (and probably Unix) distribution. Since I got crazy yesterday trying to find it again, after using it to move partitions from my old hard drive to a new one, I repost it here:
find . -depth -print0 | cpio --null --sparse -pvd /new/directory
That's it. A 1:1 copy of your filesystem hierarchy is deposited in the new directory. It saved my day.

No comments: