문제

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.

도움이 되었습니까?

해결책

I ended up using rsync -R to solve this.

다른 팁

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
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top