![특정 깊이의 하위 폴더를 사용하여 재귀적으로 rsync](https://linux55.com/image/60520/%ED%8A%B9%EC%A0%95%20%EA%B9%8A%EC%9D%B4%EC%9D%98%20%ED%95%98%EC%9C%84%20%ED%8F%B4%EB%8D%94%EB%A5%BC%20%EC%82%AC%EC%9A%A9%ED%95%98%EC%97%AC%20%EC%9E%AC%EA%B7%80%EC%A0%81%EC%9C%BC%EB%A1%9C%20rsync.png)
폴더에 재귀적으로 액세스 하고 싶지만 rsync
특정 깊이의 하위 폴더에만 액세스하고 싶습니다.
예를 들어 다음과 같이 깊이가 1, 2, 3 또는 4인 하위 폴더를 원합니다.
source/
├── subfolder 1
│ ├── subsubfolder
│ │ ├── subsubsubfolder
│ │ │ └── wanted with depth 4.txt
│ │ └── wanted with depth 3.txt
│ └── wanted with depth 2.txt
├── subfolder 2
│ └── wanted with depth 2.txt
└── wanted with depth 1.txt
답변1
--exclude=
선택하기 쉽습니다 .
깊이 2(폴더 및 하위 폴더 내의 파일)로 동기화하려면:
rsync -r --exclude="/*/*/" source/ target/
그것은 당신에게 이것을 줄 것입니다:
target/
├── subfolder 1
│ └── wanted with depth 2.txt
├── subfolder 2
│ └── wanted with depth 2.txt
└── wanted with depth 1.txt
깊이 3(폴더, 하위 폴더 및 하위 폴더의 파일)으로 동기화하려면 다음을 수행하세요.
rsync -r --exclude="/*/*/*/" source/ target/
당신에게 줄 것입니다 :
target/
├── subfolder 1
│ ├── subsubfolder
│ │ └── wanted with depth 3.txt
│ └── wanted with depth 2.txt
├── subfolder 2
│ └── wanted with depth 2.txt
└── wanted with depth 1.txt