How to copy only header files to the entire subdirectory in another directory, keeping the same hierarchy after copying to a new folder

I have a directory with a lot of header files (.h) and other .o and .c files and other files. There are many nested directories inside this directory. I want to copy only the header files to a separate directory, preserving the same structure in the new directory.

cp -rf oldDirectory newDirectorywill copy all files. I want to copy only the header files.

+5
source share
3 answers
(cd src && find . -name '*.h' -print | tar --create --files-from -) | (cd dst && tar xvfp -)

- cpio, , , , , mv'ing. ( !), . , dst src - , :

  • find src -name '*.h' -print | cpio -pdlv dst
  • mv dst/src/* dst/.
  • rmdir dst/src
+7
cp -rf oldDirectory/*.h newDirectory

- ( )

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

this one worked for me:

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

from here

+1
source

All Articles