The most commonly used packaging program under Linux is tar. Packages produced using the tar program are often called tar packages. The commands for tar package files usually end with .tar. After generating the tar package, you can use other programs to compress it, so first let’s talk about the basic usage of the tar command: There are many options for the tar command (you can view it with man tar), but the commonly used ones are So here are a few options, here are some examples: # tar -cf all.tar *.jpg This command is to package all .jpg files into a package named all.tar. -c means generating a new package, -f specifies the file name of the package.
# tar -rf all.tar *.gif
This command is to add all .gif files to the all.tar package. -r means adding files.
# 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.
# tar -tf all.tar
This command is to list all files in the all.tar package, -t means to list files
# tar -xf all.tar
This command is to extract all.tar For all files in the package, -x means unpacking
The above is the most basic usage of tar. In order to facilitate users to compress or decompress files while packaging and unpacking, tar provides a special function. This is that tar can call other compression programs while packaging or unpacking, such as calling gzip, bzip2, etc.
1) tar calls gzip
Gzip is a compression program developed by the GNU organization. Files ending in .gz are the results of gzip compression. The opposite decompression program to gzip is gunzip. Use the -z parameter in tar to call gzip. Let’s give an example
:
# tar -czf all.tar.gz *.jpg
This command is to package all .jpg files into a tar package and compress it with gzip to generate a
gzip compressed file. The package name is all.tar.gz
# 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 capabilities. Files ending in .bz2 are the results of bzip2 compression.
The decompression program opposite to bzip2 is bunzip2. Use the -j parameter in tar to call gzip. Let’s take an example to explain:
# tar -cjf all.tar.bz2 *.jpg
This command is to type all .jpg files into a tar package and compress it with bzip2 to generate a
bzip2 compressed file. The package name is all.tar.bz2
# 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 not as many people use compress as gzip and bzip2
. Files ending in .Z are the result of bzip2 compression. The decompression program opposite to compress is uncompress
. Use the -Z parameter in tar to call compress. Let’s give an example below:
# tar -cZf all.tar.Z *.jpg
This command is to package all .jpg files into a tar package and compress it with compress to generate
an uncompressed compressed file. Package, the package name is all.tar.Z
# 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 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
uncompress all.Z
7) For files ending with .tar.Z
tar -xZf all.tar.z
In addition, for the common compressed files .zip and .rar under Windows, Linux also has corresponding methods to decompress them
They:
1) For .zip
Linux provides zip and unzip programs, zip is Compression program, unzip is the decompression program. They have many parameters and options. Here is a brief introduction and an example to illustrate their usage:
# zip all.zip *.jpg
This command is to compress all .jpg files into a zip package
# 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 remember that RAR for Linux is not free; download RAR for Linux 3.2.
0 from http://www.rarsoft.com/download.htm, then install:
# 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 many parameter options. Here is just a brief introduction. I will still give an example to illustrate their usage:
# 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.
# unrar e all.rar
This command is to extract all the files in all.rar
That’s it, we have introduced tar, gzip, gunzip, bzip2, bunzip2, compress, uncompress, zip under Linux , unzip, rar, unrar and other programs, you should already be able to use them to .tar, .gz, .tar.gz, .tgz, .bz2, .tar.bz2, .Z, .tar.Z, .zip, . These 10 types of rar compressed files have been decompressed. In the future, you should not have to worry about downloading a software but not knowing how to decompress it under Linux. And the above method is 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, . Perform
operations on 10 types of compressed files: tgz, .bz2, .tar.bz2, .Z, .tar.Z, .zip, and .rar.
The following additions
tar
-c: Create a compressed archive
-x: Decompress
-t: View the content
-r: Append files to the end of the compressed archive
-u: Update the files in the original compressed package
These five are independent commands. One of them is 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: Display all processes
-O: Unpack the file to standard output
The following parameter -f It is necessary
-f: Use the file name. Remember, this parameter is the last parameter, and can only be followed by the file name.
# tar -cf all.tar *.jpg This command is to package all .jpg files into a package named all.tar. -c means generating a new package, and -f specifies the file name of the package.
# tar -rf all.tar *.gif
This command is to add all .gif files to the all.tar package. -r means adding files.
# 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.
# tar -tf all.tar
This command is to list all the files in the all.tar package, -t means to list the files
# tar -xf all.tar
This command is to unpack the all.tar package All files in, -x means unzip
Compression
tar –cvf jpg.tar *.jpg //Package all jpg files in the directory into tar.jpg
tar –czf jpg.tar.gz *.jpg // After packaging all the jpg files in the directory into jpg.tar, and compressing them with gzip, a gzip-compressed package is generated and named jpg.tar.gz
tar –cjf jpg.tar.bz2 *.jpg // After all the jpg files in the directory are packaged into jpg.tar, and compressed with bzip2, a bzip2-compressed package is generated and named jpg.tar.bz2
tar –cZf jpg.tar.Z *.jpg //Convert the directory After all the jpg files in are packaged into jpg.tar, and compressed with compress, a umcompress-compressed package is generated, named jpg.tar.Z
rar a jpg.rar *.jpg //Rar format compression requires First download rar for linux
zip jpg.zip *.jpg //Zip format compression, you need to download zip for linux first
Unzip
tar –xvf file.tar //Unzip tar package
tar -xzvf file.tar.gz //Extract tar.gz
tar -xjvf file.tar.bz2 //Extract tar.bz2
tar –xZvf file.tar.Z //Extract tar.Z
unrar e file.rar //Extract rar
unzip file. zip //Decompress zip
Summary
1. Use tar –xvf to decompress *.tar
2. Decompress *.gz with gzip -d or gunzip
3. Decompress *.tar.gz and *.tgz with tar –xzf
4. *.bz2 Use bzip2 -d or bunzip2 to decompress
5. *.tar.bz2 Use tar –xjf to decompress
6. *.Z Use uncompress to decompress
7. *.tar.Z Use tar –xZf to decompress
8 , *.rar, use unrar e to decompress
9, *.zip, use unzip to decompress
For more related articles on tar.gz, tar, bz2, zip and other decompression and compression commands under Linux, please pay attention to PHP Chinese website!