LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-15-2009, 07:54 AM   #1
Branflakes
LQ Newbie
 
Registered: Apr 2009
Posts: 5

Rep: Reputation: 0
Extract file with wildcard from .tar.gz


I've tried the other solutions posted around the internet and I either get unknown function modifiers or checksum errors.

I'm looking to get a specific filename with a wildcard extension from a .tar.gz file.

As I said, I've been searching on the internet for a while now, trying several different methods and nothing has been working for me.


I may be wrong, but it seems most people don't have to use -S when using gzip? Could this be why I am having problems?


This is what I normally do to extract one:
gzip -d -S .gz file.tar.gz
tar -xpf file.tar
 
Old 04-15-2009, 08:43 AM   #2
bhaslinux
Member
 
Registered: Oct 2003
Location: UnitedKingdom
Distribution: Debian Lenny
Posts: 351

Rep: Reputation: 47
file1
file2
file3

tar zcvf /tmp/files.tbz file? <- creates

tar zxvf /tmp/files.tbz file? <- extracts based on wildcard

works !
 
Old 04-15-2009, 08:49 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Usually you have not to use the -S option, unless you want to use a suffix different from .gz. Anyway, the way the gzipped archive has been created should not prevent file extraction, unless the archive is corrupted for some reason. Can you post what exactly you're trying to do (the exact command) and what does not work (any error messages)? Does the command tar -ztvf file.tar.gz give the correct list of files inside the archive?
 
Old 04-15-2009, 08:59 AM   #4
Branflakes
LQ Newbie
 
Registered: Apr 2009
Posts: 5

Original Poster
Rep: Reputation: 0
77629$ tar -ztvf file.tar.gz
tar: z: unknown function modifier
Usage: tar {c|r|t|u|x}[BDeEFhilmnopPqTvw@[0-7]][bfk][X...] [blocksize] [tarfile] [size] [exclude-file...] {file | -I include-file | -C directory file}...
 
Old 04-15-2009, 09:04 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Quote:
Originally Posted by Branflakes View Post
77629$ tar -ztvf file.tar.gz
tar: z: unknown function modifier
Ok. This tell us that you don't have the GNU tar installed on this machine. Which OS are you running on?

The -z option of GNU tar tells to uncompress the gzipped archive. You can do the same in two passages:
Code:
gunzip file.tar.gz
tar tvf file.tar
 
Old 04-15-2009, 09:20 AM   #6
Branflakes
LQ Newbie
 
Registered: Apr 2009
Posts: 5

Original Poster
Rep: Reputation: 0
Oh thats right ... it's Solaris 10 now
 
Old 04-15-2009, 09:31 AM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Ok. From the tar manual page on Solaris:
Quote:
Filename substitution wildcards cannot be used
for extracting files from the archive; rather, use a
command of the form:

tar xvf... /dev/rmt/0 `tar tf... /dev/rmt/0 | grep 'pattern' `
For example if you want to extract all the files with suffix ".c", just do:
Code:
tar xvf file.tar `tar tf file.tar | grep .c$`
 
Old 04-15-2009, 09:42 AM   #8
Branflakes
LQ Newbie
 
Registered: Apr 2009
Posts: 5

Original Poster
Rep: Reputation: 0
From the code you sent, wouldn't at least one of those be .tar.gz and not just .tar?

Also, what if I know the file name and need a wildcard extension? Would I have to do anything different?
 
Old 04-15-2009, 09:46 AM   #9
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Quote:
Originally Posted by Branflakes View Post
From the code you sent, wouldn't at least one of those be .tar.gz and not just .tar?
No. Since the tar command does not have the ability to uncompress the archive (option -z as stated above) you have to uncompress it previously using the gunzip (or gzip -d) command. Once you have the uncompressed .tar file you can extract it.
Quote:
Originally Posted by Branflakes View Post
Also, what if I know the file name and need a wildcard extension? Would I have to do anything different?
Just use a different pattern in the grep command! For example, suppose you want to extract file.txt, file.dat and file.asc, just do
Code:
tar xvf file.tar `tar tf file.tar | grep file.`
 
Old 04-15-2009, 10:02 AM   #10
Branflakes
LQ Newbie
 
Registered: Apr 2009
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks for the help ...

Our server doesn't have enough free space to do this (we have MASSIVE files), so I've copied all tar files to a (windows) desktop and will uncompress them that way
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
extract file from tar ust Linux - Newbie 8 03-31-2009 08:23 AM
how to extract tar.gz file ???/ wahaha Linux - Software 6 10-27-2007 09:33 AM
extract tar.gz file manolakis Linux - Newbie 3 11-13-2006 11:49 AM
can not extract the tar.gz file sharad durgawad Linux - Software 3 10-05-2005 03:41 AM
How to extract a tar.gz file? deWin Linux - Newbie 3 11-10-2004 12:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration