简体   繁体   English

如何将整个嵌套目录中的头文件仅复制到另一个目录,在复制到新文件夹后保持相同的层次结构

[英]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,它就会混淆 - 如果它不仅仅是一个副作用:

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

this one worked for me: 这个对我有用:

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

from here 这里开始

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.

相关问题 如何以递归方式将目录复制到另一个目录并仅替换未更改的文件? - How can I recursively copy a directory into another and replace only the files that have not changed? 如何将具有相同后缀的所有文件复制到另一个目录? -Unix - How to copy all the files with the same suffix to another directory? - Unix 如何将具有符号链接的文件夹复制到另一个目录 - How do i copy a folder having symbolic link to another directory 如果文件不在另一个目录中,则将文件复制到目录 - Copy files to directory if they are not in another directory 如何在bash中使用相同的名称但扩展名相同的目录复制多个文件? - How can I copy multiple files in the same directory with different names but same extension in bash? 仅在下面的目录中查找和同名文件,然后复制到其他目录 - Find and files of same name only in directory below and copy to a different directory 留在另一个文件夹中,如何从另一个目录中压缩特定文件? - Staying in another folder, how can i tar specific files from another directory? 如何将文件名更改为数字的文件复制到同一目录中 - How do I copy files in the same directory with a number changed of filename 如何用新的标头和尾部字符串替换目录中所有文件的标头和尾部,但最多只能确定一个字符? - How do I replace the header and trailer of all files in a directory with a new header and trailer string, but only up to a certain character? 如何将特定文件从目录复制到新目录 zsh - How to copy specific files from directory into new directory zsh
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM