[英]How can i copy only header files in an entire nested directory to another directory keeping the same hierarchy after copying to new folder
I have a directory which has a lot of header files(.h) and other .o and .c files and other files. 我有一个目录,其中包含许多头文件(.h)和其他.o和.c文件以及其他文件。 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. cp -rf oldDirectory newDirectory
将复制所有文件。 I want to copy only header files. 我想只复制头文件。
(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. 你可以用cpio做类似的事情,如果你只想硬链接文件而不是复制它们,但是之后可能需要一点点mv'ing。 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: 如果dst需要有一个src,它就会混淆 - 如果它不仅仅是一个副作用:
cp -rf oldDirectory/*.h newDirectory
或类似的东西(取决于实际路径)
find oldDirectory -type f -name "*.h" -print0 | xargs -file cp file newDirectory
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.