how to copy dir by excluding some subdir?

Nigel Wade nmw at ion.le.ac.uk
Fri Oct 20 16:32:16 UTC 2006


yonas Abraham wrote:
> i want to copy one directory with big sub directory and files on it
> with the exception of some of its sub directories.
> 
> I usually just do cp -r A B, and go to B and delete the once that I
> don't need it. But this becomes expensive as the size of the subdir
> gets bigger and bigger.
> 
> I was hopping something like cp -r --exclude=C A B, to copy dir A to B
> with the exception of dir C which is a sub dir of A. But man cp,
> didn't give me such thing.
> 
> any help?
> 
> Thanks
> 

Maybe tar could do this with the --exclude option (not sure if it works with 
directories), using the typical pipe to extract to a destination on the fly.

Or with cpio:

find some/dir | grep -v some/dir/to/exclude | cpio -pdm /dest

-- 
Nigel Wade, System Administrator, Space Plasma Physics Group,
             University of Leicester, Leicester, LE1 7RH, UK
E-mail :    nmw at ion.le.ac.uk
Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555




More information about the fedora-list mailing list