I want to create an empty directory structure bar2 from a nonempty directory tree bar1.
Both bar1 and bar2 are at the same hierarchical level. How can I use mkdir in an efficient manner so that intermediate directories are automatically created?
- To create a directory list from bar1 with find and order it if necessary.
- Using
awk, remove all branches from the list so that I can run `mkdir only on the leaves. - Run
mkdirwith the list to replicate the directory structure of bar1
The hard part of your question (how to list only leaf directories) has been asked before on SO. You can use the
find/awkcombo there and runmkdir -pon each result: