How to copy every file with extension X while keeping the original folder structure? (Unix-like systems)

前端 未结 2 1339
迷失自我
迷失自我 2021-01-26 00:56

I am trying to copy every HTML file from an src folder to a dist folder. However, I should like to preserve the original folder structure and if the dist folder does not exist I

2条回答
  •  孤独总比滥情好
    2021-01-26 01:36

    In the case you don't have a version of bash with the --parents option, cpio is awesome.

    [ -d _dist/ ] || cd _src && find . -name '*.html' | cpio -pdm _dist && mv _dist ..
    

    This would recursively copy all html files into _dist while maintaining the directory structures.

    ↳ GNU cpio manual - GNU Project

提交回复
热议问题