10

Due to a Hard disk problem I am trying to shift a partition from one hard disk to another. I am following http://www.ibm.com/developerworks/library/l-partplan.html article to do that. In the copying part I would like to ignore one particular sub directory. How can I accomplish that keeping in mind when copying I have to preserve my owner group and time stamp. There is around 700 GB of data that needs to be copied if I do not ignore a particular subdirectory.

12

rsync -ax --exclude [relative path to directory to exclude] /path/from /path/to

You might want (or not) to use --del as well. Check the manual page.

  • Yes that did the trick. This works.. – P Roy Jun 13 '10 at 9:32
2

Normally I use cpio as follows,

cd source_dir; find . -depth | cpio -pdmv dest_dir

And since this is a pipeline you can put a "subtraction filter" in the middle.

cd sourcedir; find . -depth | grep -v exclude_dir | cpio -pdmv dest_dir

or you could split this is into several steps,

cd source_dir; find . -depth > files.lst
gedit files.lst  # (take out the offending directory and files and save back to files.lst)
cpio -pdmv dest_dir < files.lst

Of course I'd test this on something smaller first but you get the idea.

0

You could write a simple bash script with a loop to ignore the certain path you don't want copied and copy the rest. Another solution could be to us regular expressions. You can read up on bash scripting here -> http://tldp.org/LDP/Bash-Beginners-Guide/html/Bash-Beginners-Guide.html Regex tutorial here -> http://www.regular-expressions.info/

0

Can you temporarily move (mv) the large subdirectory to some other location, do the copy, and then restore the subdirectory? I can't see a direct option in cp to do this.

  • I too checked man cp there is no way to ignore using cp. I have 550 GB of data in that sub directory and mv that might take hours. – P Roy Jun 13 '10 at 8:14
  • I assumed mv would be a relatively low-cost operation - updating references to the data rather than physically moving it around on the disk. At least, I've always found moves in Windows to be way quicker than copies - the Linux file system could work entirely differently. – Ash Jun 13 '10 at 8:50
  • mv to the same hard disk is fast. But when one does a mv across hardisks I think it takes the same time as a cp. – P Roy Jun 13 '10 at 10:56
  • I meant to move it somewhere on the same hard disk to get it out of the way, then copy the remaining to the remote disk, then move the big file back. Unless you're copying the entire disk from /. – Ash Jun 14 '10 at 0:21
0

Rather ugly solution but... why not just cp everything in the directory non recursively, and then copy the individual directories over recursively?

-1

So why not just

cp -Rv [SRC] [DEST] | grep -v [EXCLUDE]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.