bsdtar "--exclude"를 사용하여 하위 디렉터리만 제외하는 방법은 무엇입니까?

bsdtar "--exclude"를 사용하여 하위 디렉터리만 제외하는 방법은 무엇입니까?

GNU tar(예: gtar) 에서 --excludeglob 옵션은 디렉토리 자체가 아닌 하위 디렉토리에만 일치합니다. 예를 들어, --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\/*'

관련 정보