Red Hat Topics - tar question

This is Interesting: Free IT Magazines  
Home > Archive > Red Hat Topics > September 2004 > tar question





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author tar question
Mark Taylor

2004-09-15, 11:11 am

I think I did something stupid, although not fatal.

I created a tar file and upon looking at the contents I see all files are
preceeded with ../ as in:

.../thisdirectory/thisfile

Now, I need to extract a single file out of this archive and cannot get it
to do so. Is there any way to extract a single file out of this archive?


Thanks
Mark

Alois Steindl

2004-09-15, 11:11 am

Mark Taylor <mtaylorx@xlrim.com> writes:

> I think I did something stupid, although not fatal.
>

It seems that you didn't read the manuals sufficiently carefully. It's
not fatal, you can (and should) still do so.

> I created a tar file and upon looking at the contents I see all files are
> preceeded with ../ as in:
>
> ../thisdirectory/thisfile
>
> Now, I need to extract a single file out of this archive and cannot get it
> to do so. Is there any way to extract a single file out of this archive?
>

Yes,
you have to give the name of the file exactly the way as it appears in
the tar listing, eg. ../thisdirectory/thisfile
And it is extracted to just that place.

Different tar (or pax) versions also support the extraction to other
places.

Alois
Mark Taylor

2004-09-15, 11:11 am

Alois Steindl <Alois.Steindl@tuwien.ac.at> wrote in
news:u7fz5z1hw9.fsf@mch2pc28.mechanik.tuwien.ac.at:

> Mark Taylor <mtaylorx@xlrim.com> writes:
>
> It seems that you didn't read the manuals sufficiently carefully. It's
> not fatal, you can (and should) still do so.
>
> Yes,
> you have to give the name of the file exactly the way as it appears in
> the tar listing, eg. ../thisdirectory/thisfile
> And it is extracted to just that place.
>
> Different tar (or pax) versions also support the extraction to other
> places.
>
> Alois
>


That's what I would have thought, but I get the error:

tar: ../thisdirectory/thisfile: Member name contains `..'
tar: Error exit delayed from previous errors


Still working on it...

Paul Lutus

2004-09-15, 11:11 am

Mark Taylor wrote:

/ ...

> That's what I would have thought, but I get the error:
>
> tar: ../thisdirectory/thisfile: Member name contains `..'
> tar: Error exit delayed from previous errors
>
>
> Still working on it...


Try not preceding the path with "../", and also look at the output of:

$ tar -t

which should produce a list of the tar's contents, complete with appropriate
path names. What I am saying is you need to specify the file and path
exactly as it is shown in the listing, then consider changing the path
prefix as an experiment.

--
Paul Lutus
http://www.arachnoid.com

Mark Taylor

2004-09-15, 11:11 am

Paul Lutus <nospam@nosite.zzz> wrote in
news:10jh88lorjne77a@corp.supernews.com:

> Mark Taylor wrote:
>
> / ...
>
>
> Try not preceding the path with "../", and also look at the output of:
>
> $ tar -t


Which is how I discovered the ../ was preceeding the file names in the
archive.


I have tried:

tar -xzf archive.tar.gz '../dirname/filename'
tar -xzf archive.tar.gz ../dirname/filename
tar -xzf archive.tar.gz dirname/filename


I'm not sure where else to go with this.


Thanks for all the help. Please keep the ideas coming.


Paul Lutus

2004-09-15, 11:11 am

Mark Taylor wrote:

> Paul Lutus <nospam@nosite.zzz> wrote in
> news:10jh88lorjne77a@corp.supernews.com:
>
>
> Which is how I discovered the ../ was preceeding the file names in the
> archive.
>
>
> I have tried:
>
> tar -xzf archive.tar.gz '../dirname/filename'
> tar -xzf archive.tar.gz ../dirname/filename
> tar -xzf archive.tar.gz dirname/filename


At this stage, why not dump the entire archive, and swear to read the
documentation the next time?

To extract the entire archive, why not try this:

$ mkdir -p temp/sub
$ cd temp/sub
$ tar -xzf (path-to-archive)/archive.tar.gz .

If my hunch is correct, TAR will put the file tree in the parent directory
of "sub".

--
Paul Lutus
http://www.arachnoid.com

Mark Taylor

2004-09-15, 11:11 am

Paul Lutus <nospam@nosite.zzz> wrote in
news:10jhkqflsgjvf01@corp.supernews.com:

> Mark Taylor wrote:
>
>
> At this stage, why not dump the entire archive, and swear to read the
> documentation the next time?
>
> To extract the entire archive, why not try this:
>
> $ mkdir -p temp/sub
> $ cd temp/sub
> $ tar -xzf (path-to-archive)/archive.tar.gz .
>
> If my hunch is correct, TAR will put the file tree in the parent
> directory of "sub".
>


Didn't work.


Scott Hemphill

2004-09-15, 11:11 am

Mark Taylor <mtaylorx@xlrim.com> writes:

> Alois Steindl <Alois.Steindl@tuwien.ac.at> wrote in
> news:u7fz5z1hw9.fsf@mch2pc28.mechanik.tuwien.ac.at:
>
>
> That's what I would have thought, but I get the error:
>
> tar: ../thisdirectory/thisfile: Member name contains `..'
> tar: Error exit delayed from previous errors
>
>
> Still working on it...


That's right. Tar doesn't permit ".." to be in the path unless you use
-P (or --absolute-paths).

Scott
--
Scott Hemphill hemphill@alumni.caltech.edu
"This isn't flying. This is falling, with style." -- Buzz Lightyear
Mark Taylor

2004-09-15, 11:11 am

Paul Lutus <nospam@nosite.zzz> wrote in
news:10jh88lorjne77a@corp.supernews.com:

> Mark Taylor wrote:
>
> / ...
>
>
> Try not preceding the path with "../", and also look at the output of:
>
> $ tar -t
>
> which should produce a list of the tar's contents, complete with
> appropriate path names. What I am saying is you need to specify the
> file and path exactly as it is shown in the listing, then consider
> changing the path prefix as an experiment.
>


Done that Paul, as stated earlier... Guess there is no way to do it. I'll
still work on it some, but the underlying problem has been fixed. The
script that creates that bad tar file to begin with.

Thanks all for your suggestions.

Mark

Scott Hemphill

2004-09-15, 11:11 am

Mark Taylor <mxtaylorx@xlrim.netx> writes:

> Paul Lutus <nospam@nosite.zzz> wrote in
> news:10jh88lorjne77a@corp.supernews.com:
>
>
> Done that Paul, as stated earlier... Guess there is no way to do it. I'll
> still work on it some, but the underlying problem has been fixed. The
> script that creates that bad tar file to begin with.


Yes, there's a way to do it. I already posted a response. Use the
"-P" flag (or "--absolute-paths").

Scott
--
Scott Hemphill hemphill@alumni.caltech.edu
"This isn't flying. This is falling, with style." -- Buzz Lightyear
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com