There are many applications on Linux that compress and decompress files.
These tools temporarily shrink unused files or directories and save disk space.
It is very useful to save files in one file for easy backup, transfer to another directory, or transfer to another computer.
t is also useful for compressing large files; Compressed files take up less disk space and download faster over the Internet.
The Linux administrator typically uses the tar command because it plays a key role in the backup process.
It holds multiple files together and reduces the overall file size and saves time and bandwidth when moving them over the network or the Internet.
In this article, we will discuss seven common abbreviation methods: tar, zip, gzip, bzip2, 7zip, zstd and peazip.
1) How to Use the zip and unzip Command to Compress and Decompress Files on Linux
zip and unzip command is a compression and file packaging application for Linux, Unix, Windows & Mac OS X.
It is useful to compress normal files into one or more compressed files in a single zip archive.
It contains the following information about a files (File name, path, date and time of last modification, protection, and file integrity).
Both applications are available on all major Linux distributions and can be installed using the distribution official package manager.
Run the command below to compress the file using the zip command
# zip [FileName.zip] [Files To Be Compressed]
To test this, we are going to compress the “service1.sh” and “service2.sh” files into a “shell-script.zip” file.
# zip shell-script.zip service1.sh service2.sh adding: service1.sh (deflated 25%) adding: service2.sh (deflated 36%)
Use the zipinfo command to view the list of files in the ZIP archive without extracting it.
# zipinfo shell-script.zip Archive: shell-script.zip Zip file size: 639 bytes, number of entries: 2 -rwxr-xr-x 3.0 unx 157 tx defN 19-Aug-16 16:59 service1.sh -rwxr-xr-x 3.0 unx 312 tx defN 19-Aug-16 16:58 service2.sh 2 files, 469 bytes uncompressed, 317 bytes compressed: 32.4%
Use the zip command below to decompress the file
# zip -d [FileName.zip]
Use the unzip command below to decompress the file
# unzip [FileName.zip]
2) How to Use the gzip and gunzip Command to Compress and Decompress Files on Linux
The gzip and gunzip command is one of the compression methods in Linux.
It compresses regular files and adds the
.gz extension at the end of each file. Specifically, it ignores symbolic links.
This compression is much better compared to the zip compression.
gzip reduces the size of the named files using Lempel-Ziv coding (LZ77). Gzip retains the same ownership, access and modification time.
Compression is always performed even if the compressed file is slightly larger than the original.
Run the command below to compress the file using the gzip command
# gzip [Files To Be Compressed]
Use the gzip command below to decompress the file
# gzip -d [FileName.gz]
Use the gunzip command below to decompress the file
# gunzip [FileName.gz]
3) How to Use the bzip2 and bunzip2 Command to Compress and Decompress Files on Linux
The bzip2 and bunzip2 command is another compression method in Linux.
It is a high quality data compressor compared to others.
bzip2 compress files using the Burrows-Wheeler block sorting text compression algorithm, and Huffman coding.
The compressed file ends with the following extension, such as .bz2, .bz, .tbz2 or .tbz, bzip2.
To compress the file using the bzip2 command.
# bzip2 [Files To Be Compressed]
To decompress the file using the bzip2 command.
# bzip2 -d [FileName.bz2]
To decompress the file using the bzcat command.
# bzcat -dc [FileName.bz2]
To decompress the file using the bunzip2 command.
# bunzip2 [FileName.bz2]
4) How to Use the tar Command to Create a Archive File on Linux
The Linux tar command stands for
tap archive, is an archive tool that is commonly called a set of files (which can contain any type of file).
It is commonly used for data backup. The archive may be a regular file or device (eg tape drive).
If you are looking for the best compression, you can use gzip and bzip2 with the tar command. It can be restored as needed.
To create a .tar archive file.
# tar -cvf [FileName.tar] [Files/Folders To Be Compressed]
To create a .tar.gz archive file.
# tar -zcvf [FileName.tar.gz] [Files/Folders To Be Compressed]
To create a .tar.bz2 archive file.
# tar -jcvf [FileName.tar.bz2] [Files/Folders To Be Compressed]
To Decompress a .tar archive file.
# tar -xvf [FileName.tar]
To Decompress a .tar.gz archive file.
# tar -xzvf [FileName.tar.gz]
To Decompress a .tar.bz2 archive file.
# tar -xjvf [FileName.tar.bz2]
5) How to Use the 7-zip Command to Create a Archive File on Linux
7-Zip command is a new file archive that has the highest compression ratio. It uses the LZMA and LZMA2 compression algorithm.
It support various archive formats such as 7z, ZIP, CAB, ARJ, GZIP, BZIP2, TAR, CPIO, RPM and DEB.
The compression ratio in the new 7z format is 30-50% better than the ratio in the ZIP format. It uses plugins to handle archives.
To compress the file using the 7-Zip command.
# 7z a [FileName.7z] [Files To Be Compressed]
To decompress the file using the 7z command.
# 7z e [FileName.7z]
6) How to Use the zstd Command to Compress and Decompress File on Linux
Zstandard command stands for zstd, it is a real-time lossless data compression algorithm that provides high compression rates.
It was created by Yann Collet on Facebook. It offers a wide range of options for compression and decompression.
It also provides a special mode for small data known as dictionary summary.
To compress the file using the zstd command.
# zstd [Files To Be Compressed] -o [FileName.zst]
To decompress the file using the zstd command.
# zstd -d [FileName.zst]
To decompress the file using the unzstd command.
# unzstd [FileName.zst]
7) How to Use the PeaZip Command to Compress and Decompress Files on Linux
PeaZip is a free and open-source file archive utility, based on Open Source technologies of 7-Zip, p7zip, FreeArc, PAQ, and PEA projects.
It’s Cross-platform, full-featured and user-friendly alternative to WinRar and WinZip archive manager applications.
It supports its native PEA archive format (featuring volume spanning, compression and authenticated encryption).
It was developed for Windows and later added support for Unix/Linux as well. It’s currently support 188 file extensions.
Hope this article was useful for you. Kindly provide your valuable feedback/comments in the commenting section.
Stay tuned with us !!