Easy Tutorial
❮ Awk Built In Functions State Vs Strategy ❯

Comprehensive Explanation of Linux tar.gz, tar, bz2, zip, and Other Compression and Decompression Commands

Category Programming Technology

Commonly used compression and decompression commands in Linux include: tar, gzip, gunzip, bzip2, bunzip2, compress, uncompress, zip, unzip, rar, unrar, etc.


tar

The most commonly used packaging command is tar. Packages created with the tar program are often referred to as tar packages, and the file names of tar package files usually end with .tar. After creating a tar package, other programs can be used for compression, so let's first talk about the basic usage of the tar command.

There are many options for the tar command (you can check with man tar), but only a few are commonly used. Here are some examples to illustrate:

# tar -cf all.tar *.jpg

This command packages all .jpg files into a package named all.tar. -c indicates creating a new package, and -f specifies the file name of the package.

# tar -rf all.tar *.gif

This command adds all .gif files to the existing package all.tar, with -r indicating the addition of files.

# tar -uf all.tar logo.gif

This command updates the logo.gif file in the original tar package all.tar, with -u indicating the updating of files.

# tar -tf all.tar

This command lists all files in the package all.tar, with -t indicating listing files.

# tar -xf all.tar

This command extracts all files from the package all.tar, with -x indicating extraction.

The above is the most basic usage of tar. To facilitate users in compressing or decompressing files while packaging or unpacking, tar provides a special feature. This is that tar can call other compression programs during packaging or unpacking, such as calling gzip, bzip2, etc.

1) tar Invocation

gzip is a compression program developed by the GNU organization, and files ending with .gz are the result of gzip compression. The corresponding decompression program for gzip is gunzip. The -z parameter is used in tar to call gzip. Here are some examples:

# tar -czf all.tar.gz *.jpg

This command packages all .jpg files into a tar package and compresses it with gzip, generating a gzip-compressed package named all.tar.gz.

# tar -xzf all.tar.gz

This command extracts the package created above.

2) tar Invocation of bzip2

bzip2 is a compression program with even greater compression capability, and files ending with .bz2 are the result of bzip2 compression.

The corresponding decompression program for bzip2 is bunzip2. The -j parameter is used in tar to call bzip2. Here are some examples:

# tar -cjf all.tar.bz2 *.jpg

This command packages all .jpg files into a tar package and compresses it with bzip2, generating a bzip2-compressed package named all.tar.bz2.

# tar -xjf all.tar.bz2

This command extracts the package created above.

3) tar Invocation of compress

compress is also a compression program, but it seems that fewer people use compress than gzip and bzip2. Files ending with .Z are the result of compress compression. The corresponding decompression program for compress is uncompress. The -Z parameter is used in tar to call compress. Here are some examples:

# tar -cZf all.tar.Z *.jpg

This command packages all .jpg files into a tar package and compresses it with compress, generating a package compressed by uncompress named all.tar.Z.

# tar -xZf all.tar.Z

This command extracts the package created above.

With the knowledge above, you should be able to extract various compressed files. Next, let's summarize the tar series of compressed files:

1) For files ending with .tar

tar -xf all.tar

2) For files ending with .gz

gzip -d all.gz
gunzip all.gz

3) For files ending with .tgz or .tar.gz

tar -xzf all.tar.gz
tar -xzf all.tgz

4) For files ending with .bz2

bzip2 -d all.bz2
bunzip2 all.bz2

5) For files ending with tar.bz2

tar -xjf all.tar.bz2

6) For files ending with .Z

un
Download address: [https://www.rarlab.com/download.htm](https://www.rarlab.com/download.htm) (Currently the latest is RAR 5.60 for Linux), always use the most recent version.

After downloading, install with the following commands:

tar -xzpvf rarlinux-x64-5.6.b5.tar.gz

cd rar

make


This completes the installation. After installation, you will have the 'rar' and 'unrar' commands. 'rar' is the compression command, and 'unrar' is the decompression command. They have many options, here are some examples of their usage:

rar a all *.jpg


This command compresses all .jpg files into a single rar package named 'all.rar', and the .rar extension will automatically be appended to the package name.

unrar e all.rar


This command extracts all files from 'all.rar'.

** TREE

** 463***[email protected]

-

** FSAcdf

** sdf***[email protected]

Here is how to compress and decompress .tar.gz format files

**1. Compression command:**

Command format:

tar -zcvf compressed_filename.tar.gz filename_to_compress


You can switch to the current directory first, and both the compressed filename and the filename to compress can include paths.

**2. Decompression command:**

Command format:

tar -zxvf compressed_filename.tar.gz


The decompressed files can only be placed in the current directory.

** FSAcdf

** sdf***[email protected]

-

** Qi Xiangnan

** 394***[email protected]

** [Reference address](https://blog.csdn.net/weixin_40412301/article/details/81025675)

**Compress multiple specified files into one file**

- -z or --gzip or --ungzip Process the backup file with the gzip command.

- -c or --create Create a new backup file.

- -v or --verbose Display the process of the command execution.

- -f<backup file> or --file=<backup file> Specify the backup file.

Compress files file1 and file2, and the compressed file is my.tar.gz

tar -zcvf my.tar.gz file1 file2 ```

** Qi Xiangnan

* 394**[email protected]

** Reference address

** Click to share my notes

Cancel

-

-

-

❮ Awk Built In Functions State Vs Strategy ❯