LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 06-05-2007, 06:56 AM   #1
[KIA]aze
Member
 
Registered: Jun 2006
Distribution: Debian, Ubuntu, Windows XP
Posts: 146

Rep: Reputation: 16
How can I extract only *.c files from a tar.gz?


How can I extract only *.c files from a tar.gz?
 
Old 06-05-2007, 07:39 AM   #2
{BBI}Nexus{BBI}
Senior Member
 
Registered: Jan 2005
Location: Nottingham, UK
Distribution: Mageia 5, Linux Lite
Posts: 4,312

Rep: Reputation: 209Reputation: 209Reputation: 209
Use an archive manager like ark.
 
Old 06-05-2007, 08:22 AM   #3
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
This worked for me:
Code:
 tar xvfz archive.tar.gz "*.c"
The quotes are important so that the shell doesn't parse the wildcard, but instead passes it to tar.
 
Old 06-05-2007, 03:11 PM   #4
[KIA]aze
Member
 
Registered: Jun 2006
Distribution: Debian, Ubuntu, Windows XP
Posts: 146

Original Poster
Rep: Reputation: 16
Ah, of course, the quotes...should have thought of that. Thanks.

I tried with --wildcards but that didn't work and for the exclude option, I would have needed the opposite regular expression and I don't know how to do that (is it even possible?).
 
Old 06-05-2007, 03:37 PM   #5
forrestt
Senior Member
 
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 99
Just to be redundant, you can also just escape the * with a \

Code:
tar -zxvf archive.tar.gz \*.c
 
Old 06-05-2007, 10:58 PM   #6
[KIA]aze
Member
 
Registered: Jun 2006
Distribution: Debian, Ubuntu, Windows XP
Posts: 146

Original Poster
Rep: Reputation: 16
The "--wildcards" still seems to be necessary, otherwise I get this:
Quote:
tar: Pattern matching characters used in file names. Please,
tar: use --wildcards to enable pattern matching, or --no-wildcards to
tar: suppress this warning.
tar: *.c: Not found in archive
tar: Error exit delayed from previous errors
So it's:
Quote:
tar -zxvf archive.tar.gz --wildcards "*.c"
 
Old 06-06-2007, 04:02 AM   #7
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Hmmm... that's odd. I tried it on an archive with at least one directory in it (to check it wasn't getting everything from the first directory level only) without the --wildcards option and it extracted the files I specified with no trouble. Perhaps it's a version issue?... I'm using tar (GNU tar) 1.13.25.
 
Old 06-06-2007, 04:39 AM   #8
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 63
Or if you're using bash, this should work too:
Code:
tar -xvzf archive.tar.gz -T <(tar -tzf archive.tar.gz | grep '\.c$')
Yves.
 
  


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
tar - extract to different directory hcclnoodles Linux - Newbie 4 03-05-2011 03:47 PM
can not extract the tar.gz file sharad durgawad Linux - Software 3 10-05-2005 02:41 AM
tar extract fails dgermann Linux - Newbie 8 08-28-2004 11:26 AM
How to extract tar.bz2 files? akihandyman Linux - Newbie 3 12-21-2003 03:17 PM
Choosing where to extract tar.gz Arclite Linux - Software 14 08-14-2003 03:57 PM


All times are GMT -5. The time now is 04: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