-
특정 파일/폴더 제외하고 복사하기linux 2022. 6. 9. 18:10
방법
방법 1)
cp
와!
문자를 같이 사용하면 된다.cp source/!(file.txt|test.jpg|nodir) destination
만약 파일 구조가 다음과 같다하자.
. ├── destination └── source ├── file.rtf ├── file.txt ├── test.jpg ├── yes | └── test.jpg └── nodir └── other.jpg
위 커맨드 수행시 다음과 같이 된다.
. └── source (not modified) └── destination ├── file.rtf └── yes └── test.jpg
방법 2)
rsync
를 사용하면 된다.rsync -av --exclude='path1/to/exclude' --exclude='path2/to/exclude' source destination
여기서
source
와source/
는 다르다. /로 끝난다면source
폴더에 있는 파일들을destination
에 복사한다는 내용이다. /로 끝나지 않는 경우는source
폴더를destination
에 복사한다는 것이다.제외해야할 파일/폴더가 너무 많다면
--exclude-from=FILE
을 사용하면 된다. 여기서FILE
은 제외할 파일이나 폴더를 포함하는 파일의 이름이다.-av
는 archive 모드, verbose를 의미한다.--exclude
에서 wildcard를 사용할 수 있다.--exclude=\*./svn\*
참고
https://askubuntu.com/questions/333640/cp-command-to-exclude-certain-files-from-being-copied