Copy directory in GnuParallel

427 views Asked by At

I have a basic job to do: I want to copy the contents of one directory to another location by preserving all the structure inside it (subfolders and files). The size of this directory is very large, and I would like to perform the copy in parallel using GnuParallel. However, I cannot seem to manage to find the proper command to do so.

find . -print0 | parallel -0 cp -r dirToCopy/ newDirLocation/

doesn't seem to do anything, while

find . -print0 | parallel -0 cp {} newDirLocation/

copies only the files inside my original directory, without preserving the structure and the hierarchy where files are placed (basically it copies files without subfolders).

Which is the correct way to copy this directory preserving the directory content?

1

There are 1 answers

0
Ole Tange On

You need to do that in 2 stages. Create directories:

find . -type d -print0 | parallel -0 mkdir newDirLocation/{}

Create files:

find . -type f -print0 | parallel -0 cp newDirLocation/{}

Be aware that if you disk is a single 1 spindle harddisk, then it is most likely slower to do the copying in parallel. Only way to know for sure it to try it and measure it.