
나는 거대한 파일(총 ~ 1TB)의 디렉토리를 가지고 있으며 복사하고 싶지 않습니다. 그러나 나는 이 문제를 해결하고 싶기 때문에 내가 액세스할 수 있는 디렉터리 계층 구조(즉, 내가 만든 디렉터리)에 연결하는 것이 편리할 것입니다. 그래서
/path/to/dirs/
foo
bar
baz/
tri
다음 위치로 복사해야 합니다.
~/path/to/dirs/
foo -> /path/to/dirs/foo
bar -> /path/to/dirs/bar
baz/
tri -> /path/to/dirs/tri
답변1
GNU를 사용하면:
cd ~/path/to/dirs || exit 1
find /path/to/dirs -type d -printf %P\\0 | xargs -0 mkdir -p
find /path/to/dirs -type f -print0 |
xargs -0 cp --symbolic-link --parents --target-directory=.
답변2
GNU coreutils 사용(즉, 내장되지 않은 Linux 또는 Cygwin에서):
cp -al /path/to/dirs ~/path/to/dirs
cp
옵션이 없는 경우 -l
첫 번째 단계를 수행하여 디렉터리 계층 구조를 만든 다음 기호 링크에 대해 두 번째 단계를 수행합니다.
find /path/to/dirs -type d -exec sh -c 'for x do mkdir "$HOME$x"; done' _ {} +
find /path/to/dirs ! -type d -exec sh -c 'for x do ln -s "$x" "$HOME$x"; done' _ {} +
원하는 경우 두 단계를 단일 명령으로 결합할 수 있습니다.
find /path/to/dirs -exec sh -c '
for x do
if [ -d "$x" ]; then
mkdir "$HOME$x"
else
ln -s "$x" "$HOME$x"
fi
done
' _ {} +
답변3
cp --no-dereference orig dest
복사할 때 심볼릭 링크가 유지됩니다. 문서는 다음과 같습니다.
-P, --no-dereference never follow symbolic links in SOURCE
-p same as --preserve=mode,ownership,timestamps