홈 디렉토리에 다음 구조의 폴더가 있습니다.
top-tree
+-- .git
+-- branch1
| +-- branch11
| +-- .idea
| +-- branch111
| +-- branch112
| +-- branch113
| +-- branch114
| +-- branch1141
| +-- branch1142
| +-- branch1143
| +-- branch115
| +-- branch116
| +-- branch117
이제 전체 내용을 tar하고 싶지만 .git
and .idea
와 같은 모든 숨겨진 디렉토리와 branch114
최소 2 개의 하위 디렉토리가 있는 특정 디렉토리 를 제외해야합니다 (하위 디렉토리의 수는 수시로 다를 수 있음).
다음 매개 변수와 함께 tar 명령을 사용하여이를 시도했습니다.
tar -czvf archive.tar.gz --exclude=~/top-tree/branch1/branch11/branch114 --exclude=~/top-tree/.git --exclude=~/top-tree/branch1/branch11/.idea top-tree/
tar -czvf archive.tar.gz --exclude=~/top-tree/branch1/branch11/branch114 --exclude=~/top-tree/.*
그러나 위의 어느 것도 작동하지 않는 것 같습니다. 매번 폴더의 전체 내용은 top-tree
archive.tar.gz에 저장됩니다. 나는 것들 (I 포함한 여기 인용 수 없을 정도로 많은 많은 밖으로 시도 한 이 등 매개 변수의 순열과 함께 연주,이 웹 사이트 및 다른 사람의 제안을) 이 문제처럼하지만, 다른 유사한 질문 달리, 내 보인다 경로와 함께 . 내가 사용하는 tar 버전은 1.29입니다. 왜 작동하지 않습니까?
양식의 경로를 보관하고 양식의 경로를 제외합니다 . 제외 패턴은 어떤 것과도 일치하지 않습니다.top-tree/stuff
/home/skrowten/top-tree/stuff
간단한 해결책은
tar -czvf archive.tar.gz --exclude=top-tree/branch1/branch11/branch114 --exclude=top-tree/.git --exclude=top-tree/branch1/branch11/.idea top-tree
예를 들어 a가 있으면 top-tree/subdir/top-tree/.git
이것도 제외됩니다. 이를 피하는 방법은 명령 줄 경로를로 시작 하고 루트에만 표시 ./
되는 사실에 의존하는 .
것입니다.
tar -czvf archive.tar.gz --exclude=./top-tree/branch1/branch11/branch114 --exclude=./top-tree/.git --exclude=./top-tree/branch1/branch11/.idea ./top-tree
선행이 ./
당신을 괴롭 히면 --transform='s!^\./!!'
tar 호출에 옵션 을 추가하십시오 .
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다