Operating System - Linux
1827808 Members
2274 Online
109969 Solutions
New Discussion

Using tar to extract a group of specific files from archive

 
Andrew Kaplan
Super Advisor

Using tar to extract a group of specific files from archive

If I want to extract a group of files from a tar archive that have a specific extension, which, if either will work, of the following methods should I use?

1. tar xvf /path/to/device/file *.extension

2.
a.tar -tvf /path/to/device/file > filename.txt
b.vi ./filename.txt and remove any file that does not have the extension
c.sh -c 'tar xvf /path/to/device/file $(cat ./filename.txt)'
A Journey In The Quest Of Knowledge
4 REPLIES 4
Alexander Chuzhoy
Honored Contributor

Re: Using tar to extract a group of specific files from archive

the first will sure work...
Michael Schulte zur Sur
Honored Contributor

Re: Using tar to extract a group of specific files from archive

Hi Andrew,

first should work, but use "*.extension
", so that the shell doesnt expand the *.

greetings,

Michael

Mark Grant
Honored Contributor

Re: Using tar to extract a group of specific files from archive

Just to clarify the previous post.

Because the shell will expand the "*" before tar actually runs, if you have a lot of files with the ".extension" extension in your current directory, tar will try and extract those files from the archive instead of files in the archive with that extension.
Never preceed any demonstration with anything more predictive than "watch this"
Elmar P. Kolkman
Honored Contributor

Re: Using tar to extract a group of specific files from archive

And that is why option 2 might be the better of the two. That way you are sure the shell won't interfere with what you are trying to do. Especially since you need to use single quotes, not double, if you want to keep the shell out of it ;-)
Every problem has at least one solution. Only some solutions are harder to find.