▷ 7 ways to compress and decompress files in Linux » 【2022】

More and faster are always two things we want, especially when it comes to data. The problem is that “more” and “faster” are often at odds, which is why we have file compression. There are different ways to compress and decompress files in Linux, and we’ll show you the methods behind them.

Compress and decompress with Zip on Linux

Linux has various compression tools built into almost all distributions, commonly referred to as Linux distros. Zip is probably the most popular. The Zip utility can be used in the graphical user interface (GUI) or in the terminal.

Zip in Linux GUI

  1. Navigate to the files to compress and select them. Then right click and select Compress.
  1. Enter a name for the compressed file. Note that you can also choose two other types of compression. This may vary between distros.
  1. You will soon see your compressed file. Note that the file size is much smaller than the total size of the files it contains.

Unzip in Linux GUI

  1. Find the zipped file to unzip and right-click on it. To select Extract here Where extract to…. Extra Here places the content in this directory. Extract to… allows you to select another location to place the content.

The files are extracted. Note that they are back to their maximum size of 100MB each.

Archive manager to unpack in Linux GUI

Some Linux distributions have other decompression methods built-in. In this example, you can use Archive Manager.

  1. Right click on the file and select Open with file manager.
  1. Highlight the files to extract by simply clicking on them. You can select one, some or all of them. Then select Extract in the upper left corner.
  1. At this point, you can choose where to extract the files using the file manager. Then select Extract in the upper right corner.
  1. Once the extraction is complete, you can continue or view files.

The file returns to its normal size. A copy is left inside the folder.

zip files in linux terminal

Open the terminal and navigate to the directory where the files to be compressed are located. Enter the command zip ziptest.zip *.

Zipper tells linux to use the zip utility, ziptest.zip tells you the desired name for the file, the asterisk

is a wildcard meaning to compress all files in this directory.

It compresses the files, lists them and indicates how badly it has deflated or compressed them. Many actions can be used with the zip command. To see them enter zip-help,

and you will see something like the following image.

Unzip the files in the Linux terminal In Terminal, use the commandunzip ziptest.zip or relax is the command and ziptest.zip

is the name of the file to unpack.

It will show the files being unzipped, so you know when it’s done. Just like the zip command, many actions can be used with the unzip command. To see them enter decompress – help,

and you will see something like the following image.

Bzip2 to compress and decompress files in Linux

Bzip2 is another compression utility built into most Linux distributions. An important difference is that bzip2 cannot compress multiple files into a single file. Each file gets its own compressed file.

Zip files in Linux terminal with Bzip2 Enter the command bzip2 -kv9 test1.txt file test2.txt file

where bzip2 is the command. -kv9 breaks down into k medium, mediumk keep the originals v medium, mediumv erbose so we can see what’s going on, and 9

for the highest level of compression. You can choose between 1 and 9. The higher the compression level, the longer it will take to compress the files.

The output tells us more than zip, but the end result is almost the same.

Unzip files in Linux terminal with Bzip2 Enter the commandbzip2 -kvd testfile.1.txt.bz2 testfile2.txt.bz2 . the -kvd the options break down into k fork save files, v forv windy outing, and D forD

ecocompress

You’ll see the files unzip and you’ll know when it’s done. To see bzip2 options, enter bzip2 –help,

and you will see the following. Play around with options on non-critical files just to see what they can do.

Gzip to compress and decompress files in Linux This is the last of the popular compression utilities that are included with most distributions. is lighter than bzip2 and Postal code

for options. However, the compression quality remains the same.

Files compressed in a Linux terminal with Gzip Enter the commandgzip2 -kv9 testfile.1.txt testfile2.txt . the -kv9 the options break down into k fork save files, v forv windy outing, and 9

for the highest compression level between 1 and 9.

As the detailed output shows, gzip performs just as well as other compression methods.

Unzip files in Linux terminal with Gzip

There are two ways to unzip gzip files. One is to use gzip and the other is to gunzip. For him gzip order, usegzip -kvd testfile1.txt.gz testfile2.txt.gz . Notice the D option. It means thatD

ecocompress For him firearm order, usegunzip file test1.txt.gz file test.2.txt.gz

. The only difference with gzip is that gunzip does not require options for basic decompression.

What about tar to compress and decompress files in Linux? Why don’t you tar

has it already been mentioned? It’s an archiving tool that takes a bunch of files and puts them into a single file for easy portability. Regardless of the file size, the tar file size will be about the same.

But if you combine a zip method with tar, you get something really cool. You get a single package of very well compressed files.

Using the other zip methods on a directory of files will result in a zip file for each file in the directory. Using tar with the gzip option on the directory compresses everything and creates an archive.

Zip files in Linux Terminal with Tar and Gzip Enter the commandtar -czvf Documents.tgz Documents

. the -czvf the options break down into VS forVS create a new file, zcompress with gz IPs, v forv windy outing, and F forF

file equals file, which means file retains the file structure of the original directory. The new file must have a name, which is Documents.tgz in this example. When using the .tgz file extension, others will know it is a tar file that has been compressed. At last documents

is the directory to archive and compress.

The output looks like the following.

In the file manager you can see the tar file and that it is compressed.

Unzip files in Linux terminal with Tar and Gzip

To unpack a gzip-compressed tar file, it’s the same tar command with slightly different options. Enter the commandtar -xzvf Documents.tgz Documents

. the -xzvfthe options break down into x for eX leaflet, zunpack with gzIPs v verbose so we can see what’s going on, and F for file=archive means keep file structure. Documents.tgz is the file to unzip and unzip, and documents

is the directory you want the content to go to.

The results are shown in the image below. Both files have returned to their normal size and are in the Documents directory. To display the tar options, enter tar -help,

and you will get several pages of options. Note that there are different zip methods available besides gzip, so you can choose whichever you prefer.

Less Popular Zip Tools on Linux

There are two other compression utilities in most Linux distributions. However, they are not so popular. However, they are listed here, so you know them.

LZMA

LZMA is another command-line compression utility often found in Linux distributions. This is the compression algorithm used by 7-Zip.

XZ

The XZ utility is a command-line compression tool that is often included with Linux distributions. Its options are similar to bzip2. It is based on the LZMA2 algorithm, itself based on LZMA. More information about these utilities can be found using the commands lzma – help andxz-help

.

Aren’t there other ways to compress and decompress in Linux?