UNIX, how to maintain directory structure?

I want to create an empty directory structure bar2from a non-empty directory tree bar1. Both bar1and bar2are at the same level of hierarchy. How can I use mkdirit effectively so that staging directories are automatically created?

  • To create a directory list from bar1 using find, order it if necessary.
  • Using awk, remove all branches from the list so that I can run `mkdir only on sheets.
  • Run mkdirwith a list to replicate the directory structure bar1
+1
source share
3 answers

( ) SO. find/awk mkdir -p :

[bar1] $ find . -type d | sort | awk '$0 !~ last {print last} {last=$0} END {print last}' | xargs -Ix mkdir -p ../bar2/x
+2
cd bar1
find . -type d -exec mkdir -p '../bar2/{}' \;
+6

Instead, you can use rsync :

rsync -r -f '+ */' -f '- *' bar1 bar2

which is more detailed:

rsync --verbose --recursive --include '*/' --exclude '*' bar1 bar2
+2
source

All Articles