Thursday, September 8, 2011

// // Leave a Comment

How to Extract a Single Folder From a tarball (tar.gz) in 1 Command

Using this command you can extract a single file or folder from a tarball having an extension of tar.gz.
Sometimes we have a large tarball containing a number of files and folders. But we want to extract a single file or folder from that.

Now to do this in linux using commands ?

Open the command prompt or login to SSH and type the below commands after editing as per requirements.

gunzip -c /full path to tarball/filename.tar.gz | tar -xvf - path of file in the tarball/filename.zip

Now in the above codes first you will need to put the full path of the tar.gz file. Then second you will put the path of file you want to extract inside your tarball ie tar.gz.

Lets take an example:- Suppose we have a tarball named tarball.tar.gz containing 2 zip files namely file1.zip and file2.zip.
Assuming that the tarball.tar.gz is inside our home/ directory .
Now we want to extract the file1.zip from the tarball. So we can use the below code for doing so.

gunzip -c /home/tarball.tar.gz | tar -xvf - file1.zip

Enjoy !

0 comments:

Post a Comment