Reputation: 93
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
Upvotes: 2
Views: 2403
Reputation: 50750
export src=$1/. dest=$2
find "$src" -type d -exec bash -c 'printf "%s\0" "${@//"$src"/"$dest"}"' sh {} + | xargs -0 mkdir -p
Upvotes: 2
Reputation: 103814
You could use rsync to copy files and/or directories.
To copy directories only, set --max-size=0
and no files will be copied.
Example:
rsync -r -n -v --max-size=0 src_path/ dest_path
^ recursive
^ dry run - nothing copied
^ verbose
^ no files
^ src path
^ use a trailing / if you don't
want the src_path created
at dest
^ dest path
Upvotes: 1