Reputation: 297
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?
awk
, remove all branches from the list so that I can run `mkdir only on the leaves.mkdir
with the list to replicate the directory structure of bar1Upvotes: 1
Views: 1211
Reputation: 948
You might want to use rsync instead:
rsync -r -f '+ */' -f '- *' bar1 bar2
which is, more verbose:
rsync --verbose --recursive --include '*/' --exclude '*' bar1 bar2
Upvotes: 2
Reputation: 175395
The hard part of your question (how to list only leaf directories) has been asked before on SO. You can use the find
/awk
combo there and run mkdir -p
on each result:
[bar1] $ find . -type d | sort | awk '$0 !~ last {print last} {last=$0} END {print last}' | xargs -Ix mkdir -p ../bar2/x
Upvotes: 2