[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-tar] Trouble with tar -xzf when using --files-from=-

From: Tony Olekshy
Subject: Re: [Help-tar] Trouble with tar -xzf when using --files-from=-
Date: Wed, 21 Oct 2015 06:30:39 -0600
User-agent: KMail/4.10.5 (Linux/3.11.10-100.fc18.x86_64; KDE/4.10.5; x86_64; ; )

Tony Olekshy wrote, on 2015-10-20 at 19:20 MDT:
> Hello.
> I'm having trouble understanding why I can't pipe the output of a
> tar -tzf a.tgz ... through to a tar -xzf a.tgz --files=from=- ...
> without producing what appear to be spurious messages. In practice
> I want to place a filter in that pipeline to select just what to
> extract, but the following script simplifies that out to just show
> the problem I'm encountering.

Reuti wrote, on 2015-10-21 at 04:32 MDT:
> Accessing "." in the archive will move its pointer already to
> the end:
> $ echo . | tar tf archive.tgz --files-from=-
> ./
> ./foo/
> ./foo/bar

Reuti wrote, on 2015-10-21 at 05:10 MDT:
> Ah, although I missed the --no-recursion at the first glance: its
> position is important. It must appear before the --files-from=- in
> your case.

Perfect, that did it. The attached script with the --no-recursion
placed before the --files-from=- does exactly what I'm looking for,
and I've tested it with a filter between the tar -t and the tar -x
(a simple head -2 works for this testing), and it all works well.

Thank you very much for you assistance with this matter, Reuti. Now
I understand the difference between tar's globally scoped options &
those that only apply to succeeding arguments.

Yours, &c, Tony Olekshy

set -v #----------------------------------------------------------------

: Step 1: Create the testing environment...
export TAR=/bin/tar TEST=~/test

echo; $TAR --version | grep 'GNU tar'

mkdir -p $TEST/from/foo $TEST/into
rm -rf $TEST/archive.tgz $TEST/into/*
date > $TEST/from/foo/bar

: Step 2: Show the contents of $TEST...
echo; cd $TEST; find . | sort | xargs ls -ld

: Step 3: Create $TEST/archive.tgz...
cd $TEST/from; find . -print0   \
    | $TAR -v --create --gzip --format=gnu --force-local --seek    \
        --sparse --no-recursion --null --no-unquote --files-from=- \

: Step 4: Show the contents of archive.tgz...
cd $TEST; $TAR --list --gzip --format=gnu --force-local \

: Step 5: Extract files from archive.tgz using --files-from...
: In practice the head -2 in this pipeline will be a filter,
: the --files-from will be \0-separated, and there will be a
: --null option before the --no-unquote.
cd $TEST; $TAR --list --gzip --format=gnu --force-local            \
        --file=$TEST/archive.tgz | head -2 | ( cd $TEST/into;      \
    $TAR -v --extract --gzip --format=gnu --force-local --seek     \
        --sparse --overwrite --no-recursion --no-unquote           \
        --files-from=- --file=$TEST/archive.tgz                    )

: Step 6: Show the contents of $TEST...
echo; cd $TEST; find . | sort | xargs ls -ld

exit #------------------------------------------------------------------

reply via email to

[Prev in Thread] Current Thread [Next in Thread]