Description of file compression and decompression parameters under Linux platform

Time:2022-1-2

Faced with some suffixes tar, tar gz、tar. Bz2… I’m a little confused,
In fact, if you understand it, it will be solved easily.

First of all, we should clarify the concept that packaging and compression under Linux are two different things,
That is, you can package the file, but not compress it.

Let’s take an example:
There is a folder named wallpaper in my root directory, which contains some wallpaper,
I’ll package this folder now, but not compress it.
Directly enter tar CVF wallpaper Tar wallpaper enter generates a wallpaper package.
The operation process is as follows:

attachments/200511/08_154042_cvf.jpg

Tar here is a package command, and CVF is a parameter,
C means to create a packaged file (if it is replaced by X, it means unpacking), and V displays the file during compression,
F is to use the file name, then add the package name you want to generate, and then add the compressed directory.

Now that we have learned to package, we will compress it:
Enter gzip wallpaper Enter tar and a wallpaper is generated tar. GZ.

attachments/200511/08_154249_gzip.jpg

Gzip here is a compression command. Do you have to use tar to package and then gzip to compress,
In fact, it doesn’t need to be so troublesome. Just add the parameter Z after tar to have the function of gzip. In other words, just use:
tar zcvf wallpaper. tar. GZ wallpaper this command can directly generate wallpaper tar. GZ file.
The process is as follows:

attachments/200511/08_154450_tarzc.jpg

This is how to create a compressed package. Files compressed with different programs will have different suffixes,
For example, the suffix of the file compressed by compress is * z. Compressed with bzip2 is * bz2,
Zip is used to compress * Zip, etc., the most common of which is * tar. bz2. And * tar. GZ (also known as tarball file)

As in the above example, if we use bzip2 wallpaper Tar to package it, the generated file is wallpaper tar. bz2,
Specific command parameters can be viewed with command – help.

After the compressed package is created, the next step is to decompress it. As in the above example, we are now working on wallpaper tar. GZ for decompression,
There are two methods:
1. First unzip the compressed package with gzip and parameter D, and then unpack it with tar and parameter X. As shown in the figure:

attachments/200511/08_154332_gziptar.jpg

2. Directly use tar plus the parameters Z and xvf to decompress and unpack. In fact, Z here adds the function of gzip.

attachments/200511/08_154541_zxvf.jpg

This is also the most commonly used method. Similarly, if the suffix is * tar. Bz2 file, just replace Z with J,
As mentioned earlier, tar has integrated the functions of gzip and bzip2, just add different parameters to them.
Then adding J here indicates that tar has the function of bzip2.

We know that under windows, we can double-click the compressed package file to see what is in it without unpacking it,
Similarly, we can do this under Linux. Just add the parameter t after tar to view the contents of the compressed package,
But I don’t understand opening it.

For example, let’s take a look at wallpaper tar. What exactly is in GZ? You can enter:

attachments/200511/08_154808_t.jpg

Another thing I want to say is that the suffix of the compressed package actually has no practical significance. Don’t be confused by the suffix,
For example, we can package and compress the folder wallpaper, which can be written as follows:

attachments/200511/08_154849_tarsongzi.jpg

Generated wallpaper Songzi is a compressed file. Let’s use file to check this.

In summary, I’m just talking about some of the most commonly used commands, which can be regarded as throwing a brick to attract jade,
There are many functions that you can dig slowly. Don’t underestimate the compression command, which plays a big role in Linux backup.

Recommended Today

Check docker version and reinstall docker

This document describes how to check the docker version and reinstall docker to provide reference for friends in need. Check docker version [[email protected] ]# docker versionClient: Docker Engine – Community Version: 19.03.8 API version: 1.40 Go version: go1.12.17 Git commit: afacb8b Built: Wed Mar 11 01:27:04 2020 OS/Arch: linux/amd64 Experimental: false Server: Docker Engine – […]