Various decompression commands under Linux

This article introduces the compression programs tar, gzip, gunzip, bzip2, bunzip2, compress, uncompress, zip, unzip, rar, unrar and other programs under linux, and how to use them to compress .tar, .gz, .tar.gz, .tgz , .bz2, .tar.bz2, .Z, .tar.Z, .zip, .rar these 10 compressed files to operate

This article introduces the compression programs tar, gzip, gunzip, bzip2, bunzip2, compress, uncompress, zip, unzip, rar, unrar and other programs under linux, and how to use them to compress .tar, .gz, .tar.gz, .tgz , .bz2, .tar.bz2, .Z, .tar.Z, .zip, .rar these 10 compressed files to operate

The most commonly used package program under Linux is tar. The package produced by the tar program is often called a tar package. The commands of a tar package file usually end with .tar. After the tar package is generated, other programs can be used to compress it, so let's talk about the basic usage of the tar command first:

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

?
1
# tar -cf all.tar *.jpg

This command is to type all .jpg files into a package named all.tar. -c means to generate a new package, -f specifies the file name of the package.

?
1
# tar -rf all.tar *.gif

This command is to add all .gif files to the all.tar package. -r means to add files.

?
1
# tar -uf all.tar logo.gif

This command is to update the logo.gif file in the original tar package all.tar, -u means to update the file.

?
1
# tar -tf all.tar

This command is to list all the files in the all.tar package, -t means to list the files

?
1
# tar -xf all.tar

This command is to unpack all files in the all.tar package, -x means unpack

The above is the most basic usage of tar. In order to facilitate users to compress or decompress files while packing and unpacking, tar provides a special function. This is that tar can call other compression programs, such as calling gzip, bzip2, etc., while packing or unpacking.

1) tar call

Gzip is a compression program developed by the GNU organization, and files ending in .gz are the result of gzip compression. The decompression program opposite to gzip is gunzip. Use the -z parameter in tar to invoke gzip. Here's an example:

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

This command is to make all .jpg files into a tar package, and compress it with gzip to generate a gzip compressed package named all.tar.gz

?
1
# tar -xzf all.tar.gz

This command is to unpack the package generated above.

2) tar calls bzip2

bzip2 is a compression program with stronger compression ability, and the file ending in .bz2 is the result of bzip2 compression.

The decompressor as opposed to bzip2 is bunzip2. Use the -j parameter in tar to invoke gzip. Here's an example:

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

This command is to make all .jpg files into a tar package, and compress it with bzip2 to generate a bzip2 compressed package, the package name is all.tar.bz2

?
1
# tar -xjf all.tar.bz2

This command is to unpack the package generated above.

3) tar calls compress

compress is also a compression program, but it seems that people who use compress are not as many as gzip and bzip2. A file ending in .Z is the result of bzip2 compression. The decompression program opposite to compress is uncompress. Use the -Z parameter in tar to call compress. Here's an example:

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

This command is to make all .jpg files into a tar package, and compress it with compress to generate an uncompress compressed package, the package name is all.tar.Z

?
1
# tar -xZf all.tar.Z

This command is to unpack the package generated above

With the above knowledge, you should be able to unpack a variety of compressed files. The following is a summary of the compressed files of the tar series :

1) For files ending in .tar

tar -xf all.tar

2) For files ending in .gz

gzip -d all.gz

gunzip all.gz

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

tar -xzf all.tar.gz

tar -xzf all.tgz

4) For files ending in .bz2

bzip2 -d all.bz2

bunzip2 all.bz2

5) For files ending with tar.bz2

tar -xjf all.tar.bz2

6) For files ending in .Z

uncompress all.Z

7) For files ending in .tar.Z

tar -xZf all.tar.z

In addition, for common compressed files .zip and .rar under Windows, Linux also has corresponding methods to decompress them:

1) For .zip

zip and unzip programs are provided under linux, zip is a compression program, and unzip is a decompression program. They have a lot of parameter options, here is only a brief introduction, and still give an example to illustrate their usage:

?
1
# zip all.zip *.jpg

This command is to compress all .jpg files into a zip package

?
1
# unzip all.zip

This command is to extract all files in all.zip

2) For .rar

To process .rar files under linux, you need to install RAR for Linux, which can be downloaded from the Internet, but keep in mind that RAR for Linux is not free; RAR for Linux can be downloaded from http://www.rarsoft.com/download.htm 3.2.0 
, then install:

?
1
2
3
# tar -xzpvf rarlinux-3.2.0.tar.gz
# cd rar
# make

This is installed. After installation, there are two programs, rar and unrar, rar is a compression program, and unrar is a decompression program. They have a lot of parameter options, here is only a brief introduction, and still give an example to illustrate their usage: 

?
1
# rar a all *.jpg

This command is to compress all .jpg files into a rar package named all.rar, the program will automatically append the .rar extension to the package name.

?
1
# unrar e all.rar

This command is to extract all files in all.rar

So far, we have introduced tar, gzip, gunzip, bzip2, bunzip2, compress, uncompress, zip, unzip, rar, unrar and other programs under linux, you should be able to use them to .tar, .gz, . 10 kinds of compressed 
files have been decompressed. In the future, there should be no need to download a software without knowing it. I am troubled by how to unlock it under Linux. And the above method is also basically effective for Unix.

This article introduces the compression programs tar, gzip, gunzip, bzip2, bunzip2, compress, uncompress, zip, unzip, rar, unrar and other programs under linux, and how to use them to compress .tar, .gz, .tar.gz, .tgz , .bz2, .tar.bz2, .Z, .tar.Z, .zip, .rar these 10 compressed files to 
operate.

The following supplements 

tar
 

-c: create a compressed archive 
-x: decompress 
-t: view content 
-r: append files to the end of the compressed archive 
-u: update the files in the original compressed package

These five commands are independent, and one of them should be used for compression and decompression. It can be used in conjunction with other commands, but only one of them can be used. The following parameters are optional when compressing or decompressing archives as needed.

-z: with gzip attribute 
-j: with bz2 attribute 
-Z: with compress attribute 
-v: show all processes 
-O: unpack file to stdout 
 

The following parameter -f is required

-f: Use the file name, remember, this parameter is the last parameter, only the file name can be followed. 
 

?
1
2
# tar -cf all.tar *.jpg这条命令是将所有.jpg的文件打成一个名为all.tar的包。-c是表示产生新的包,-f指定包的文件名。
# tar -rf all.tar *.gif

This command is to add all .gif files to the all.tar package. -r means to add files. 
 

?
1
# tar -uf all.tar logo.gif

This command is to update the logo.gif file in the original tar package all.tar, -u means to update the file. 
 

?
1
# tar -tf all.tar

This command is to list all the files in the all.tar package, -t means to list the files 
 

?
1
# tar -xf all.tar

This command is to unpack all files in the all.tar package, -x means unpack

compression 

tar –cvf jpg.tar *.jpg //Pack all jpg files in the directory into tar.jpg 
tar –czf jpg.tar.gz *.jpg //After packaging all jpg files in the directory into jpg.tar, and It uses gzip compression to generate a gzip compressed package named jpg.tar.gz 
tar –cjf jpg.tar.bz2 *.jpg //After packaging all jpg files in the directory into jpg.tar, and use it with bzip2 compression, generate a bzip2 compressed package named jpg.tar.bz2 
tar –cZf jpg.tar.Z *.jpg //Pack all jpg files in the directory into jpg.tar, and compress it with compress , generate a umcompress compressed package named jpg.tar.Z 
rar a jpg.rar *.jpg //compression in rar format, you need to download rar for linux 
zip jpg.zip *.jpg //compression in zip format , you need to download the zip for linux first

decompress

tar –xvf file.tar //decompress tar package 
tar -xzvf file.tar.gz //decompress tar.gz 
tar -xjvf file.tar.bz2 //decompress tar.bz2 
tar –xZvf file.tar.Z //decompress tar.Z 
unrar e file.rar //decompress rar 
unzip file.zip //decompress zip 
 

Summarize

1. Decompress  *.tar with tar –xvf2
, *.gz decompress with gzip -d or gunzip3, *.tar.gz 
and *.tgz decompress with tar –xzf4 
, *.bz2 use bzip2 -d or use bunzip2 Unzip 
5, *.tar.bz2 with tar -xjf unzip 
6, *.Z with uncompress 
7, *.tar.Z with tar -xZf unzip 
8, *.rar with unrar e unzip 
9, *.zip with unzip unzip

Unzip RAR software download and unzip .zip and .rar files under Linux

Download address: http://www.rarsoft.com/download.htm (the latest version is RAR 3.71 for Linux)

The latest one shall prevail.

For common compressed files .zip and .rar under Windows, Linux also has corresponding methods to decompress them:

1: For .zip

zip and unzip programs are provided under linux, zip is a compression program, and unzip is a decompression program. They have a lot of parameter options, here is only a brief introduction, and examples are given to illustrate their usage:

?
1
2
# zip all.zip *.jpg(这条命令是将所有.jpg的文件压缩成一个zip包)
# unzip all.zip(这条命令是将all.zip中的所有文件解压出来)

2: For .rar

To process .rar files under linux, you need to install RAR for Linux, which can be downloaded from the Internet, but keep in mind that RAR for Linux is not free; RAR 3 can be downloaded from http://www.rarsoft.com/download.htm .60 for Linux, then install it as follows:

?
1
2
3
# tar -xzpvf rarlinux-3.2.0.tar.gz
# cd rar
# make

This is installed. After installation, there are two programs, rar and unrar. Rar is a compression program, and unrar is a decompression program. They have a lot of parameter options, give an example to illustrate their usage

?
1
# rar a all *.jpg

This command is to compress all .jpg files into a rar package named all.rar, the program will automatically append the .rar extension to the package name.

?
1
# unrar e all.rar

This command is to extract all files in all.rar.

The xxxx.tar.gz file uses tar with the zxvf parameter, which can be decompressed at one time. XXXX is the file name. E.g:
 

?
1
$tar zxvf xxxx.tar.gz

gzip -d

Syntax: gzip [-acdfhlLnNqrtvV][-S <compression suffix string>][-<compression efficiency>][--best/fast][file...] or gzip [-acdfhlLnNqrtvV][-S <compression word tail string>][-<compression efficiency>][--best/fast][directory]

Supplementary note: gzip is a widely used compression program. After the file is compressed, the extension ".gz" will be added after its name.

parameter:
 

-a or --ascii Use ASCII text mode. 
-c or --stdout or --to-stdout Output the compressed file to the standard output device without changing the original file. 
-d or --decompress or ----uncompress Uncompress the compressed file. 
-f or --force Force compress files. Ignore whether the file name or hardlink exists and whether the file is a symlink. 
-h or --help Online help. 
-l or --list List information about compressed files. 
-L or --license Display version and copyright information. 
-n or --no-name When compressing a file, do not save the original file name and timestamp. 
-N or --name When compressing a file, save the original file name and timestamp. 
-q or --quiet do not display warning messages. 
-r or --recursive Recursive processing, processing all files and subdirectories in the specified directory together. 
-S<compressed suffix string> or ----suffix<compressed suffix string> Change the compressed suffix string. 
-t or --test Test that the compressed file is correct. 
-v or --verbose Display instruction execution process. 
-V or --version Display version information. 
-<compression efficiency> The compression efficiency is a value between 1-9, the default value is "6", the larger the value specified, the higher the compression efficiency will be. 
--best This parameter has the same effect as specifying the "-9" parameter. 
--fast This parameter has the same effect as specifying the "-1" parameter.

1. Decompress *.tar with tar –xvf2
, *.gz decompress with gzip -d or gunzip3, *.tar.gz
and *.tgz decompress with tar –xzf4
, *.bz2 use bzip2 -d or use bunzip2 Unzip
5, *.tar.bz2 with tar -xjf unzip
6, *.Z with uncompress
7, *.tar.Z with tar -xZf unzip
8, *.rar with unrar e unzip
9, *.zip with unzip unzip

*.tar.gz file decompression command under Linux

1. Compression command:

Command format: tar -zcvf compressed file name.tar.gz compressed file name

You can switch to the current directory first. Both the compressed file name and the compressed file name can be added to the path.

2. Unzip command:

Command format: tar -zxvf compressed filename.tar.gz

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

You can use the zip command to process multiple files and directories at the same time by listing them one by one, separated by spaces:

zip -r filename.zip file1 file2 file3 /usr/work/school 
 

Zip a single directory command zip -r filename.zip filename

The above command compresses file1, file2, file3, and the contents of the /usr/work/school directory (assuming this directory exists) into the filename.zip file.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324453174&siteId=291194637
Recommended