Table of Contents
- Installing the necessary tools
- Decompressing the .zip file
- Extracting the .tar file
- Decompressing the .gz file
- Extracting the .tar.gz file
- Decompressing the .xz file
- Extracting the .tar.xz file
- Extracting the .tar.bz2 file
- Extracting the .7z file
Archiving is process of packaging a bunch of files or directories into a single file. Archiving is needed for better portability and to preserve the storage. There are lots of ways to creating (compressed and uncompressed) archives of the files. You can checkout the commands here.
The archive feels need to be uncompressed or extracted when we want to use files in an archive. In this post, different tools are explained to uncompress or extract different archive files.
Installing the necessary tools
Your Ubuntu distribution might have already shipped with most of the following packages. In case not, please install using the following command.
sudo apt install zip gzip bzip2 p7zip-full p7zip-rar tar xz-utils
Decompressing the .zip file
There are many tools available to extract the .zip file. We are using unzip and 7z tools below.
Extracting .zip file using unzip
Replace foo.zip with your desired zip file.
Extracting .zip file using 7z
Here is another way to extract the .zip file using 7z tool.
7z x foo.zip
Extracting the .tar file
Extracting .tar file using tar
tar is most commonly used command to archive or extract the files in Linux.
tar -xf foo.tar
Extracting .tar file using 7z
Here is another way to extract the .tar file using 7z tool.
7z x foo.tar
Decompressing the .gz file
.gz or gzip file is a compressed file. Use following commands to extract .gz file.
Decompressing .gz file using gunzip
We are using gunzip command to uncompress the .gz file. Removing -k option in the following command will replace the compressed file with extracted file.
gunzip -k foo.gz
Decompressing .gz file using 7z
7z x foo.gz
Extracting the .tar.gz file
.tar.gz file is an archive file with gzip compression.
Extraction and decompresion in a single step with tar command
tar xzvf foo.tar.gz
Decompression and extraction with gunzip and tar
To extract .tar.gz file, it need to be uncompressed first using gunzip or 7z and then need to be extracted using tar or 7z. Here is an example.
gunzip foo.tar.gz tar xf foo.tar
Decompressing the .xz file
.xz file can be extracted using unxz or 7z as mentioned in the below commands.
Decompressing .xz file using unxz
Decompressing .xz file using 7z
7z x foo.xz
Extracting the .tar.xz file
.tar.xz is an archive file with XZ compression.
Extraction and decompression in a single step using tar command
tar xJvf foo.tar.xz
Extracting and decompression in multiple steps with tar and unxz
To extract .tar.xz file, it need to be uncompressed first using unxz or 7z and then need to be extracted using tar or 7z. Here is an example.
unxz foo.tar.xz tar xf foo.tar
Extracting the .tar.bz2 file
.tar.bz2 is an archive file bzip2 compression.
Extracting and decompressing tar.bz2 file in a single step
tar xjvf foo.tar.bz2
Extracting and decompressing .tar.bz2 file in multiple steps with tar and bunzip2
To extract .tar.bz2 file, it need to be uncompressed first using bunzip2 or 7z and then need to be extracted using tar or 7z. Here is an example.
bunzip2 foo.tar.bz2 tar xf foo.tar
Extracting the .7z file
7z x foo.7z