Posted at January 5, 2017 at 4:53 pm by Jithin
In this tutorial we can learn how to extract tar.gz files using Linux Command line tools.
A .tar.gz file is nothing, but an archive. It is a file that acts as a container for other files. The tar program provides the ability to create tar archives, as well as various other kinds of manipulation. For example, you can use Tar on previously created archives to extract files, to store additional files, or to update, or list files which were already stored. An archive can contain many files, folders, and subfolders, usually in compressed form using gzip or bzip2 program on Unix operating systems. Initially, tar archives were used to store files conveniently on magnetic tape. The name “Tar” comes from this use; it stands for tape archiver. You need to use the tar command which can create and manipulate archive files in .tar.gz under Unix like operating systems. It is very useful for archiving multiple files together into a single archive file. It allows us to restore files individually. Tar can direct its output to available devices, files, or other programs (using pipes), it can even access remote devices or files (as archives). tar.gz file is actually the product of two different things. Tar basically just packages a group of files into a single file bundle, but doesn’t offer compression on it’s own. To compress tar you’ll want to add the highly effective gzip compression. In this documentation, we can discuss about how to extract the tar.gz files from the command line. For this, open a command-line terminal and then type the following commands to open and extract a .tar.gz file.
Extracting .tar.gz files
1) If your tar file is compressed using a gzip compressor, use this command to uncompress it.
$ tar xvzf file.tar.gz
x: This option tells tar to extract the files.
v: The “v” stands for “verbose.” This option will list all of the files one by one in the archive.
z: The z option is very important and tells the tar command to uncompress the file (gzip).
f: This options tells tar that you are going to give it a file name to work with.
2) To uncompress tar.gz file into a different directory, use the command below:
$ tar xvzf file.tar.gz -C /path/to/somedirectory
Where the -C argument is used to specify the path to place the file. By defaults files will be extracted into the current directory. To change the directory, we use -C option.
3) If your tarball name is data.tar.gz, enter the following command to extract files:
$ tar -xvzf data.tar.gz
A tarball is a group or archive of files that are bundled together using the tar command and have the .tar file extension.
4) To extract test.doc file from the data.tar.gz tarball, use the following command:
$ tar -xvzf data.tar.gz test.doc
5) To extract an entire archive, run the command below:
$ tar xvzf data.tar.gz
6) To view a detailed table of content by listing all files in achieve, you can use the following command:
$ tar -tvf data.tar.gz
7) To extract the .gz file without tar, you can use the following command:
$ gunzip file.gz
Extracting .tar.bz2 files
This is just about the same as the gzip decompression. The major difference is that the z option has been replaced by the j option.
If your tar file is compressed using a bZip2 compressor, use the following command to extract it.
$ tar xvjf file.tar.bz2
Where ‘j’ will decompress a bzip2 file.
If you need any further assistance please contact our support department.
You can skip to the end and leave a response. Pinging is currently not allowed.