1834652 Members
2246 Online
110069 Solutions
New Discussion

tar file

 
eric_204
Frequent Advisor

tar file

I have a tar file that contains some file with different names , i tried to extract the file with the * ( eg. tar -xvf file.tar /home/edp/* ) , but can't restore the files, could suggest how can I extract all the files ? thx.
11 REPLIES 11
eric_204
Frequent Advisor

Re: tar file

I tried restore it by the command "tar -xvf file.tar /home/edp/file1.* " then only the files begins with file1 will be restored , so I have use the below command to restore all the files , could suggest what could I do to restore all the files at one time without submit all the commands ?

"tar -xvf file.tar /home/edp/file2.* "
"tar -xvf file.tar /home/edp/file3.* "
"tar -xvf file.tar /home/edp/file4.* "
"tar -xvf file.tar /home/edp/file5.* "
"tar -xvf file.tar /home/edp/file5.* "
"tar -xvf file.tar /home/edp/file7.* "
Madhu Sudhan_1
Respected Contributor

Re: tar file

I doubt if you can extract only a file or set of files matching a pattern if the files are part of the tar ball. (May be Iam wrong)

But if you want to extract all the files of file.tar into /home/edp then use

cd /home/edp ; tar xvf /absolutepathof/file.tar

This should extract all the files of file.tar in to the current directoy.

Thanks,
Madhu
Think Positive
Adisuria Wangsadinata_1
Honored Contributor

Re: tar file

Hi Eric,

You can use the steps below to restore all files in one shoot :

# cd /home/edp
# tar -xvf file.tar /home/edp/file*

OR this to restore all :

# cd /home/edp
# tar -xvf file.tar

To list the contains of file.tar :

# tar -tvf file.tar

Hope this information can help you.

Best Regards,
AW
now working, next not working ... that's unix
Adisuria Wangsadinata_1
Honored Contributor

Re: tar file

And don't forget to move file.tar into /home/edp first before executing the command that I refer to you.

Otherwise you interact with blank file 8-).

Best Regards,
AW
now working, next not working ... that's unix
eric_204
Frequent Advisor

Re: tar file

thx , but how can I restore it to current path instead create the path /home/edp ? thx.
Stefan Schulz
Honored Contributor

Re: tar file

Hi,

if the files are stored with absolute path names in the tar file, the standard tar command will not be able to relocate them.

If you need to extract them to a different directory directly you have to look for a new tar programm. I think GNUtar (gtar) can do this.

Search for it on the porting center (e.g. http://hpux.asknet.de).

Hope this helps

Regards Stefan
No Mouse found. System halted. Press Mousebutton to continue.
Elmar P. Kolkman
Honored Contributor

Re: tar file

To do that, you could try to use pax instead of tar. Pax can handle tar files, but has options like -s to substitute patterns in the filenames...

pax -r -s///

Or use the -C option to change the root-directory used by tar to another directory, for instance /tmp, and then move the files to the correct location.
Every problem has at least one solution. Only some solutions are harder to find.
Trond Haugen
Honored Contributor

Re: tar file

Filename substitution should work but you will need to escape special characters.
If you want to restore EVERYTHING from the tar archive use:
tar -xvf file.tar
If you wish to restore everything starting with a certain pettern use:
tar -xvf file.tar /home/edp/file[2-7].\*
If you want to restore to a different path like Stefan mentioned you can also look into pax which is part of HP-UX.

Regards,
Trond
Regards,
Trond Haugen
LinkedIn
Adisuria Wangsadinata_1
Honored Contributor

Re: tar file

Hi Eric,

You can use the steps below :
For example :
other directory is /destination
file.tar at /tmp
need to restore /home/edp/*

# cd /destination
# pax -pe -rvf /tmp/file.tar -s '/^\///' /home/edp

Hope this information can help you.

Best Regards,
AW

now working, next not working ... that's unix
john korterman
Honored Contributor

Re: tar file

Hi,
you can use pax. First, copy yout tar archive to the directory in which you want to unpack it, e.g.:
# cp mytararchive.tar /mytardir

then place yourself in the directory:

# cd /mytardir

and extract the files from mytararchive.tar:
# pax -rv -s'/^\///' < ./mytararchive.tar

which will create the dir. structure of the files in mytararchive.tar and append this structure to the current dir. It is a bit of a hack and I have not tried it with a single file, only the whole tar archive. You should of course always cd to the directory where you create your tar archive and select by ./ in order to avoid this situation in future.

regards,
John K.
it would be nice if you always got a second chance
RNY
Respected Contributor

Re: tar file

Hello,
If i understood well,try the following:

for i in 2 3 4 5 6 7
do
tar -xvf file.tar /home/edp/file$i.*
done

Regards