GagA// 0n D nEt

It is currently Sun May 20, 2018 3:42 pm

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Extract Single File from tarball file using Tar
PostPosted: Sat Dec 06, 2008 11:34 pm 
Offline

Joined: Wed Jul 18, 2007 1:14 am
Posts: 181
Many a times you find the need to extract a single file or a few files out of a tarball file. But you end up extracting the whole file and then picking up the required files.

You can get this job done by using GNU Tar which can help you extract a single file or a few files out of a tarball file.

You just need to list the contents of the tarball file (in case you aren't sure about the file names). This can be done by using the -t option with tar command. The following is an example for viewing the contents of a tar file:
Quote:
[[email protected] ~]# tar -tvf gagan.tar

The following command can be used to view the contents of a gzip compression:
Quote:
[[email protected] ~]# tar -ztvf gagan.tar.gz

The following command can be used to view the contents of a bzip2 compression:
Quote:
[[email protected] ~]# tar -jtvf gagan.tar.bz2

Where,
Code:
v: Verbosely list files processed (display detailed information)
z: Filter the archive through gzip so that we can open compressed (decompress) .gz tar file
j: Filter archive through bzip2, use to decompress .bz2 files.
f filename: Use archive file called filename

Extracting a desired file out of the tarball file

So in case you wish to extract a file called linux.doc out of the compression gagan.tar, you can use the following command:
Quote:
[[email protected] ~]# tar -xvf gagan.tar linux.doc

Or if you wish to extract a file called linux.doc out of the compression gagan.tar.gz, you can use the following command:
Quote:
[[email protected] ~]# tar -zxvf gagan.tar linux.doc

Note: You can remove the -v option if you want, as this will just give you a verbose output of the command. I prefer not to use the -v option.

You can also use wildcard extraction to extract files matching a particular patter.

So this means that in case you want to extract files starting with report out of the file xyz.tar.gz without any necessary details of the directory in which these files are, you can use the following command:
Quote:
[[email protected] ~]# tar -zxf xyz.tar.gz --wildcards --no-anchored 'report*'

Or if you wish to extract all html files you can use the following command:
Quote:
[[email protected] ~]# tar -zxf xyz.tar.gz --wildcards --no-anchored '*.html'

Where,
Code:
-x: instructs tar to extract files.
-f: specifies filename / tarball name.
-v: Verbose (show progress while extracting files).
-j : filter archive through bzip2, use to decompress .bz2 files.
-z: filter archive through gzip, use to decompress .gz files.
--wildcards: instructs tar to treat command line arguments as globbing patterns.
--no-anchored: informs it that the patterns apply to member names after any / delimiter.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group