Script to find all .h file and put in specified fo

2019-09-03 04:09发布

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!

标签: bash shell bsd
2条回答
仙女界的扛把子
2楼-- · 2019-09-03 04:28

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
查看更多
Explosion°爆炸
3楼-- · 2019-09-03 04:38
find /path/to/find -name "*.h" -type f | xargs -I {} cp --parents {} /path/to/destination

Check this out.

查看更多
登录 后发表回答