Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Due to a Hard disk problem I am trying to shift a partition from one hard disk to another. I am following 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.

share|improve this question
up vote 6 down vote accepted

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.

share|improve this answer
Yes that did the trick. This works.. – P Roy Jun 13 '10 at 9:32

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.

share|improve this answer

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 -> Regex tutorial here ->

share|improve this answer

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.

share|improve this answer
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

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

share|improve this answer

So why not just

cp -Rv [SRC] [DEST] | grep -v [EXCLUDE]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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