Operating System - HP-UX
1834712 Members
2140 Online
110069 Solutions
New Discussion

Untarring multiple specific files

 
Andrew Kaplan
Super Advisor

Untarring multiple specific files

Hi there,

If I want to untar multiple files that have a specific extension, but at the same time not untar all files with that extension, will the following work?

1. cd dir/to/tar
2. ls -1 >> ../filename
3. vi ../filename (Once there, remove all files that are not to be unarchived.)
4. sh -c 'tar cvf /path/to/tarfile $(cat ../filelist)'
A Journey In The Quest Of Knowledge
7 REPLIES 7
Andrew Kaplan
Super Advisor

Re: Untarring multiple specific files

Correction to the previous message...item 4 should read: sh -c 'tar xvf /path/to/tarfile $(cat ../filelist)'
A Journey In The Quest Of Knowledge
Steve Steel
Honored Contributor

Re: Untarring multiple specific files

Hi

xvf is untar you would make a tar.

What you show should work to make a tar of only the files or to untar only the files assuming they were backed up the same way

tar -cvf tape /etc/profile

then

cd /etc
tar -xvf tape profile

Wont work.


Fbackup is much more flexible for this with the graph file system.

Steve STeel
If you want truly to understand something, try to change it. (Kurt Lewin)
Jeff Schussele
Honored Contributor

Re: Untarring multiple specific files

Hi Andrew,

You need to know the exact path to *each* file as used to tar them to do this - for EX
./path/to/file.ext
./path2/to/file2.ext
file3.ext
./path3/file4.ext
/path4/file5.ext
are all different & would need to be in "filelist" exactly as they are in the tarball whether relative as 1,2 & 4 above - or absolute as 3 & 5 above.

If they're all in the same dir, then what you propose will work - again with the caveat that the proper path be used.

Rgds,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
john korterman
Honored Contributor

Re: Untarring multiple specific files

Hi,
if you have nothing against hard manual work, try this:
# tar -xwf

the "w" option causes an interactive tar session in which you are asked to confirm restore for each file with either a "y" or "n". Slow but safe.

regards,
John K.
it would be nice if you always got a second chance
Elena Leontieva
Esteemed Contributor

Re: Untarring multiple specific files

They say that the GNU version of tar has an X flag which specifies that the matching argument to tar is the name of a file that lists files to exclude from the archive:

tar xvfX tarfile.tar exlude-list-file

Elena.
Rodney Hills
Honored Contributor

Re: Untarring multiple specific files

You could do it the way you have it layed out as long as the tar contains relative pathnames and the names you supply match precisely.

The drawback to your method is you could exceede the maximum number of characters allowed for a command line.

Check out the "pax" command. You can supply a list of filenames to it and it can restore the selected files from your tar archive.

HTH

-- Rod Hills
There be dragons...
Chris Vail
Honored Contributor

Re: Untarring multiple specific files

Here's my idea of "quick and dirty".
tar tvf /dev/yourdevice >>/tmp/filenames

This extracts the filenames from the tape and puts them into the text file /tmp/filenames.

Then edit the file with your favorite editor and remove any filenames you don't want. Lastly, use:
tar xvf /dev/yourdevice `cat /tmp/filenames`

This should work for any version of tar.


Chris