简体   繁体   English

查找所有.h文件并将其放入具有相同结构的指定文件夹的脚本?

[英]Script to find all .h file and put in specified folder with same structure?

I need a bash script like 我需要一个bash脚本

headers ~/headers-folder ~/output-folder 头文件〜/ headers-folder〜/ output-folder

so it recursively finds all .h files in ~/headers-folder and put them all in ~/output-folder with the folder hierarchy maintained? 因此,它以递归方式在〜/ headers-folder中查找所有.h文件,并将它们全部保存在〜/ output-folder中,并保持文件夹层次结构?

Thanks! 谢谢!

find /path/to/find -name "*.h" -type f | xargs -I {} cp --parents {} /path/to/destination

看一下这个。

rsync is great for that too: rsync也很适合:

rsync --include '*.h' --filter 'hide,! */' -avm headers-folder/ output-folder/

This will copy all the *.h files, and create only the necessary directories. 这将复制所有*.h文件,并仅创建必要的目录。


Example: 例:

mkdir -p headers-folder/{subdir,empty}
touch headers-folder/foo.h
touch headers-folder/subdir/foo.h

tree headers-folder

# headers-folder/
# |-- empty
# |-- foo.h
# `-- subdir
#     `-- foo.h

rsync --include '*.h' --filter 'hide,! */' -avm headers-folder/ output-folder/

tree output-folder

#  output-folder/
#  |-- foo.h
#  `-- subdir
#      `-- foo.h

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM