ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 특정 파일/폴더 제외하고 복사하기
    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

    여기서 sourcesource/는 다르다. /로 끝난다면 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

    댓글

Designed by Tistory.