Search code examples
bashfind

copy directory structure without files


Hello i am trying to make a script which takes two arguments (names of directories) and copies the structure of the first into the other.

This is my code:

cd $1 && find . -type d -exec mkdir -p /$2/{} \;

when i run the script i dont get any errors but nothing happens. What am i doing wrong please help thank you.

edit: the script is saved in home and both directories are also in home (~). i run the script in terminal:

sudo bash DN1c.sh dir1 dir2

first directory has multiple subdirectories and the second directory is empty


Solution

  • export src=$1/. dest=$2
    find "$src" -type d -exec bash -c 'printf "%s\0" "${@//"$src"/"$dest"}"' sh {} + | xargs -0 mkdir -p