How can i copy only header files in an entire nested directory to another directory keeping the same hierarchy after copying to new folder How can i copy only header files in an entire nested directory to another directory keeping the same hierarchy after copying to new folder shell shell

How can i copy only header files in an entire nested directory to another directory keeping the same hierarchy after copying to new folder


(cd src && find . -name '*.h' -print | tar --create --files-from -) | (cd dst && tar xvfp -)

You can do something similar with cpio if you just want to hard link the files instead of copying them, but it's likely to require a little mv'ing afterward. If you have lots of data and don't mind (or need!) sharing, this can be much faster. It gets confused if dst needs to have a src in it - this is, if it isn't just a side effect:

  1. find src -name '*.h' -print | cpio -pdlv dst
  2. mv dst/src/* dst/.
  3. rmdir dst/src


this one worked for me:

rsync -avm --include='*.h' -f 'hide,! */' . /destination_dir

from here


cp -rf oldDirectory/*.h newDirectory

or something like (depending on the actual paths)

find oldDirectory -type f -name "*.h" -print0 | xargs -file cp file newDirectory