How to only exclude subdirectories but not directory itself with --exclude option?

21 views
Skip to first unread message

brai...@heroku.com

unread,
Dec 4, 2017, 10:20:31 PM12/4/17
to libarchive-discuss
I'm cross-posting this from https://unix.stackexchange.com/questions/407679/bsdtar-how-to-only-exclude-subdirectories to hopefully get an answer here.

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.

Reply all
Reply to author
Forward
0 new messages