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 should like to create a new one.
Create the folder if it does not exist:
[ -d _dist/ ] || mkdir _dist/
Copy every file:
cp -R _src/**/*.html _dist/
Together:
[ -d _dist/ ] || mkdir _dist/ && cp -R _src/**/*.html _dist/
However, if I use ** only the files inside a folder will get copied and if I remove the ** only the root files will get copied. Is this even accomplishable?
This will omit empty (no html-files) dirs. But if you need them, repeat without -name "*.html" but with -type d.
In the case you don't have a version of bash with the
--parents
option,cpio
is awesome.This would recursively copy all
html
files into_dist
while maintaining the directory structures.↳ GNU cpio manual - GNU Project