Operating System - HP-UX
1833788 Members
2633 Online
110063 Solutions
New Discussion

Re: Select file to extract from tar

 
addendum
Advisor

Select file to extract from tar

I have a tar gz file that contain many many files inside , if I just want to extract one of file in this tar gz file , is it possible ?

eg .

# tar -ztvf ora.tgz

ora1.txt
ora2.txt
ora3.txt
"
"

I just want to extract ora2.txt instead of extract all files ( tar -zxvf ora.tgz ) , what can I do ? thx


5 REPLIES 5
Adisuria Wangsadinata_1
Honored Contributor

Re: Select file to extract from tar

Hi,

Can try the command below :

# tar -zxvf ora.tgz ora2.txt

Hope this information can help you.

Cheers,
AW
now working, next not working ... that's unix
Arunvijai_4
Honored Contributor

Re: Select file to extract from tar

# tar -zxvf ora.tgz ora.txt

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Arunvijai_4
Honored Contributor

Re: Select file to extract from tar

# tar -zxvf ora.tgz ora2.txt

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Bill Hassell
Honored Contributor

Re: Select file to extract from tar

tar does an exact match based on how the files were saved. Just specifying the filename like ora1.txt will return nothing is the files were stored as: /ora1/text/ora1.txt

So you must start by determing the exact name for the file as stored in the archive. The names used in the archive were taken from the method used to create the tar file or tape. If the tar command said to tar ... /ora1/text/ then the fullpath is stored in the archive and you must recover the file(s) with the same leading directories. Unlike other versions of tar, there is no option to delete leading / or to remove leading directories. Neither is there an option to restore files without the leading directories.


Bill Hassell, sysadmin
Muthukumar_5
Honored Contributor

Re: Select file to extract from tar

You can just take it as,

# tar -xvzf ora.tgz

hth.
Easy to suggest when don't know about the problem!