Skip to content

Instantly share code, notes, and snippets.

@rhettc
Created November 17, 2014 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rhettc/ba33e5b58b2dcf0c0c04 to your computer and use it in GitHub Desktop.
Save rhettc/ba33e5b58b2dcf0c0c04 to your computer and use it in GitHub Desktop.
use find to duplicate the parent directory’s structure into the current directory, files are not copied
# given the structure
../foo/bar
../fizz/bang
../beep
# move into the beep child dir and run the command
cd beep
find ../ -mindepth 1 -type d -printf "%P\0" | xargs --null mkdir
# now beep has the same structure
./foo/bar
./fizz/bang
./beep
# mindepth 1 prevents the "." from being printed as a match
# printf is used to print the leading part of the path except for the "../"
# --null tells xargs about the null terminator we included in our print format
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment