In GNU tar (i.e. gtar
), the --exclude
option with a glob only matches the subdirectories, but not the directory itself. For example, --exclude test-tar/a/b/*
would exclude anything inside of b
, but not b
itself. However, bsdtar
is excluding the directory itself as well. My question is how do I make bsdtar
act the same as GNU in this regard?
Here is an example script the demonstrates the problem:
#!/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
This outputs:
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)
My versions are tar (GNU tar) 1.29
and bsdtar 3.3.2
.