How To Extract .tar.gz Files using Linux Command Line
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
Where,
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.
A tarball is a group or archive of files that are bundled together using the tar command and have the .tar file extension.
Eg:
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.
Eg:
3) To extract test.doc file from the file.tar.gz tarball, use the following command:
$ tar -xvzf file.tar.gz test.doc
Eg:
4) To view a detailed table of content by listing all files in archive, you can use the following command:
$ tar -tvf file.tar.gz
Eg:
5) To extract the .gz file without tar, you can use the following command:
$ gunzip file.gz
Eg:
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.
Eg:
If you need any further assistance please contact our support department.
Nice explanation. Very helpful. Thanks a lot.
i have total 125 tar.gz files to unzip can you suggest a command to unzip all 125 tar.gz in a single stretch
use *.tar.gz for the file name.
If you want to extract all the tarballs at once, in one location, use wildcard characters in command. For example, if you want to unzip all the tarballs at once located in the current directory, execute
sudo tar -xzvf *.tar.gz"
. Let us know if you have more questions.So helpful, thanks a lot
i have files with multiple extension. how can i extract this kind of file 21.zip.gz.gz.gz.gz.
using just one command. 🙂
i keep getting this “not in gzip format” how can i fix that??
It could be in a different format. If you have an existing plan with us, please open a ticket with our support department: https://www.interserver.net/contact-information.html
Im using Chromebook how would i do this?
Access your Linux server via SSH using Secure Shell App or similar tools in Chromebook – https://chrome.google.com/webstore/detail/secure-shell-app/pnhechapfaindjhompbnflcldabbghjo?hl=en Then follow the steps mentioned in the tutorial.