Reputation: 19992
How to copy files from one directory to another while preserving the directory structure in mac?
I found that you can use cp --parents
in ubuntu but unfortunately that doesn't work in mac.
Upvotes: 10
Views: 10614
Reputation: 228
I'm tired of writing this manually, so I'm going to provide a non rsync way for future reference.
#!/bin/bash
cpParents() {
src=(${*: 1:-1})
dest=${*: -1:1}
for filename in $src; do
[ -e "$filename" ] || continue
dirPath=$(dirname "${filename}")
mkdir -p $dest/$dirPath
cp $filename $dest/$dirPath
done
}
Upvotes: 2
Reputation: 179
On OS X you can use ditto <source> <destination>
See here: http://osxdaily.com/2014/06/11/use-ditto-copy-files-directories-mac-command-line/
Upvotes: 7