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?
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.
Just name the folder on the command line: tar xf tar.tar x/b
Test
$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;
x
x/b
x/b/f2
x/b/d
x/b/d/f3
x/b/f1
‘nonofile’ was properly skipped but f1 f2 f3 were all extracted.