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

不打扰是莪最后的温柔 提交于 2019-12-24 19:26:46

问题


I need a bash script like

headers ~/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?

Thanks!


回答1:


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

Check this out.




回答2:


rsync is great for that too:

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

This will copy all the *.h files, and create only the necessary directories.


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


来源:https://stackoverflow.com/questions/20415760/script-to-find-all-h-file-and-put-in-specified-folder-with-same-structure

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