复制到新文件夹后,如何将整个嵌套目录中的头文件仅复制到另一个保持相同层次结构的目录 [英] How can i copy only header files in an entire nested directory to another directory keeping the same hierarchy after copying to new folder
问题描述
我有一个目录,里面有很多头文件(.h)和其他 .o 和 .c 文件以及其他文件.该目录内部有许多嵌套目录.我只想将头文件复制到一个单独的目录中,并在新目录中保留相同的结构.
I have a directory which has a lot of header files(.h) and other .o and .c files and other files. This directory has many nested directories inside. I want to copy only header files to a separate directory preserving the same structure in the new directory.
cp -rf oldDirectory newDirectory
将复制所有文件.我只想复制头文件.
cp -rf oldDirectory newDirectory
will copy all files.
I want to copy only header files.
推荐答案
(cd src && find . -name '*.h' -print | tar --create --files-from -) | (cd dst && tar xvfp -)
如果只想硬链接文件而不是复制文件,则可以使用cpio进行类似的操作,但是之后可能需要进行一些mv操作.如果您有大量数据并且不介意(或不需要!)共享,则可以更快地进行共享.如果dst需要其中包含src,则会感到困惑-这是副作用,如果不是的话:
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:
- 找到src -name'* .h'-print |cpio -pdlv dst
- mv dst/src/* dst/.
- rmdir dst/src
这篇关于复制到新文件夹后,如何将整个嵌套目录中的头文件仅复制到另一个保持相同层次结构的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!