On Sun, 20 Nov 2016 09:27:27 +0200
Sergey Poznyakoff <g...@gnu.org.ua> wrote:

> Neal P. Murphy <neal.p.mur...@alum.wpi.edu> ha escrit:
> 
> > Wait. Do I have to explicitly specify every dir in each file's path
> > when selecting a subset of files in a tarball?
> 
> Judging by the question, the following link might be of interest to you:
> 
>   http://lists.gnu.org/archive/html/bug-tar/2016-09/msg00019.html

Apologies. 30 years of using UNIX/Linux and only *now* have I noticed that this 
is how tar/cpio/rsync work.

But I thought of a fairly elegant solution: get all of the dir names. Assume 
that the list of files (with './') to extract is in pkg.list. The list is a 
subset of all of the files in pkg. Then:
----
while read path; do
  path=`dirname $path`
  while [ "$path" != "." ]; do
    echo $path
    path=`dirname $path`
  done
done < pkg.list | sort | uniq > pkg.dirs
mkdir distrib
tar xvf path/to/pkg.tar.gz -C distrib -T pkg.list -T pkg.dirs
----

Caveat: the dirs also must be in the archive.

Reply via email to