![bsdtar "--exclude"를 사용하여 하위 디렉터리만 제외하는 방법은 무엇입니까?](https://linux55.com/image/122646/bsdtar%20%22--exclude%22%EB%A5%BC%20%EC%82%AC%EC%9A%A9%ED%95%98%EC%97%AC%20%ED%95%98%EC%9C%84%20%EB%94%94%EB%A0%89%ED%84%B0%EB%A6%AC%EB%A7%8C%20%EC%A0%9C%EC%99%B8%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95%EC%9D%80%20%EB%AC%B4%EC%97%87%EC%9E%85%EB%8B%88%EA%B9%8C%3F.png)
GNU tar(예: gtar
) 에서 --exclude
glob 옵션은 디렉토리 자체가 아닌 하위 디렉토리에만 일치합니다. 예를 들어, --exclude test-tar/a/b/*
내부에 있는 모든 항목은 제외되지만 그 자체 b
는 제외되지 않습니다 b
. 그러나 bsdtar
디렉터리 자체도 포함되지 않습니다. 내 질문은 bsdtar
이와 관련하여 GNU에서도 동일한 작업을 수행하는 방법입니다 .
다음은 문제를 보여주는 샘플 스크립트입니다.
#!/usr/bin/env bash
echo -e "\nGiven an archive that looks like this:"
bsdtar -tf test.tgz
echo -e "\nExtract the archive excluding test-tar/a/b/* using gtar"
rm -rf test-tar
gtar -xzf test.tgz --exclude 'test-tar/a/b/*'
file test-tar/a/b
file test-tar/a/b/B.txt
echo -e "\nExtract the archive excluding test-tar/a/b/* using bsdtar"
rm -rf test-tar
bsdtar -xzf test.tgz --exclude 'test-tar/a/b/*'
file test-tar/a/b
file test-tar/a/b/B.txt
이 출력은 다음과 같습니다.
Given an archive that looks like this:
test-tar/
test-tar/a/
test-tar/a/A.txt
test-tar/a/b/
test-tar/a/b/B.txt
Extract the archive excluding test-tar/a/b/* using gtar
test-tar/a/b: directory
test-tar/a/b/B.txt: cannot open `test-tar/a/b/B.txt' (No such file or directory)
Extract the archive excluding test-tar/a/b/* using bsdtar
test-tar/a/b: cannot open `test-tar/a/b' (No such file or directory)
test-tar/a/b/B.txt: cannot open `test-tar/a/b/B.txt' (No such file or directory)
내 버전은 tar (GNU tar) 1.29
및 입니다 bsdtar 3.3.2
.
답변1
누군가 이 질문에 대한 답을 찾고 있다면 간단합니다. 후행 슬래시에 백슬래시를 추가하면 됩니다.
명령은 다음과 같습니다.
bsdtar -xzf test.tgz --exclude 'test-tar/a/b\/*'