Compression provides more disk space and network efficiency in IT systems. There are different types, levels, and performance compression algorithms.
tar.gz is defacto standard for Linux systems for a long time. In this tutorial, we will look at different ways to unzip or uncompress
Unzip with tar Command
tar is our old friend who can provide compress and decompress of a lot of different compression formats. We will unzip
test.tar.gz in this example with
xis used to extract
vis used for verbose mode
fis used for file mode
$ tar xvf test.tar.gz
Extract Specific File From A tar.gz
We can extract a specific file from an
*.tar.gz archive. We will just provide the file or directory name we want to extract to the end of the command. First listing the contents of the
*.tar.gz file content and then providing the file name precisely. We will list file contents with the
-tf option and extract the file named
setup.py with the
xf like below.
$ tar -tf zipstream-1.1.4.tar.gz
and extract a specific file.
$ tar -xf zipstream-1.1.4.tar.gz zipstream-1.1.4/setup.py
Unzip From Stdin or Standard Input
Linux is a very elastic operating system that provides different original features. Standard input can be used for a tar.gz file. We can unzip a
*.tar.gz data that will be fed from the standard input. We will use the
| in order to redirect the file to the
tar command. In this example, we will download the Linux kernel from
kernel.org and redirect it to the
$ wget -c http://ftp.itu.edu.tr/Mirror/Apache//httpd/httpd-2.4.39.tar.gz -O - | tar -xz
Unzip with gunzip Command
gunzip is the unzip command provided by
gzip suite. We can use this command without any option in order to unzip. But in this example, we use
-voption which is used for verbose mode.
$ gunzip -v test.tar.gz
Unzip with 7z Command
7z is my favorite compression algorithm and tool. It supports a lot of formats from zip to rar.
gz format is also supported. We can provide
e option in order to extract the
7z automatically detects the format.
$ 7z e test.tar.gz
List tar.gz Contents
If we want to unzip only some of the files from a
tar.gz archive first we need to list files. We can list files different ways but we will look only single command which is
$ tar tvf test.tar.gz
Unzip Only Specified Directory
If we need to extract only some of the files or directories we need to specify them. We will use unzip command and provide the files and directories at the end of the command we want to extract. In this example, we will extract the file
oldbackup/db.conf file from
$ tar xvf test.tar.gz oldbackup/db.conf