How can I use cp to copy a directory but ignore a certain sub directory in Linux
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.
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.
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.