I ended up using rsync -R
to solve this.
copy files while preserving directory structure in mac
سؤال
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.
المحلول
نصائح أخرى
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/
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
}
لا تنتمي إلى StackOverflow