![](/img/trans.png)
[英]How can I recursively copy a directory into another and replace only the files that have not changed?
[英]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文件以及其他文件。 該目錄里面有許多嵌套目錄。 我想只將頭文件復制到一個單獨的目錄,在新目錄中保留相同的結構。
cp -rf oldDirectory newDirectory
將復制所有文件。 我想只復制頭文件。
(cd src && find . -name '*.h' -print | tar --create --files-from -) | (cd dst && tar xvfp -)
你可以用cpio做類似的事情,如果你只想硬鏈接文件而不是復制它們,但是之后可能需要一點點mv'ing。 如果您有大量數據並且不介意(或需要!)共享,這可能會更快。 如果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.