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

我们两清 提交于 2020-08-22 05:48:19

问题


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 will copy all files. I want to copy only header files.


回答1:


(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



回答2:


this one worked for me:

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

from here




回答3:


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


来源:https://stackoverflow.com/questions/10176849/how-can-i-copy-only-header-files-in-an-entire-nested-directory-to-another-direct

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!