tar alternative to bsdtar –include

I’m trying to adapt a script that uses bsdtar, which is not available on my Linux distribution.

bsdtar -x -f <file> --include="SOME/FOLDER/"

What is the alternative of --include in tar command?

Asked By: mkrasowski


From old Solaris documentation: you can use something like:

tar -xf <file> $(tar -tf <file> |grep "SOME/FOLDER/")

For sure GNU tar may have options to define filter of files to be extracted but never used such options.

Answered By: Romeo Ninov

Just name the folder on the command line: tar xf tar.tar x/b


$rm -fr x; mkdir x x/a x/b x/b/d; touch x/nonofile x/b/f1 x/b/f2 x/b/d/f3;
 tar cf tar.tar x;
 rm -fr x; tar xf tar.tar x/b;
 find x;

‘nonofile’ was properly skipped but f1 f2 f3 were all extracted.

Answered By: minorChaos
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.