Handling of various compressed files under Linux

  • 2020-05-15 03:22:29
  • OfStack

The most commonly used packaging program under Linux is tar. Packages made using the tar program are often called tar packages, and commands in the tar package files usually end in.tar. Once the tar package is generated, you can use other programs to compress it, so let's start with the basic usage of the tar command:

There are many options for the tar command (you can see them with man tar), but there are only a few common options, as shown below

To illustrate 1:

# tar -cf all.tar *.jpg

This command is to type all.jpg files into a package called all.tar. -c is for 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 to add 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 lists all the files in the all.tar package. -t lists the files

# tar -xf all.tar

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

That's the basic use of tar. To make it easier for users to compress or unpack files while packing and unpacking, tar offers a special feature. This is where tar can call other compressors while packaging or unpacking, such as gzip, bzip2, etc.

1) tar calls gzip

gzip is a compression program developed by GNU organization. The file at the end of gz is the result of gzip compression. The decompression program opposite gzip is gunzip. tar calls gzip using the parameter -z. Example 1:

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

This command is to type all.jpg files into one tar package and compress it with gzip to produce one gzip compressed package named all.tar.gz

# tar -xzf all.tar.gz

This command is to unpack the package generated above.

2) tar calls bzip2

bzip2 is a more powerful compression program. The file at the end of bz2 is the result of bzip2 compression. The decompression program as opposed to bzip2 is bunzip2. tar calls gzip using the parameter -j.

Example 1:

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

This command is to type all.jpg files into one tar package and compress it with bzip2 to produce one bzip2 compressed package named all.tar.bz2

# tar -xjf all.tar.bz2

This command is to unpack the package generated above.

3) call compress tar

compress is also a compression program, but it seems that more people use compress than gzip and bzip2. The file at the end of Z is the result of bzip2 compression. The decompression program opposite compress is uncompress. compress is called using the parameter -Z in tar. Example 1:

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

This command is to type all.jpg files into one tar package and compress it with compress to produce one uncompress compressed package named 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 unlock a variety of compressed files, the following is a summary of the tar series of compressed files:

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.tgz or.tar.gz

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

4) for the file ending.bz2

bzip2 -d all.bz2
bunzip2 all.bz2

5) for files ending tar.bz2

tar -xjf all.tar.bz2

6) for files ending in.Z

uncompress all.Z

7) for the.tar.Z ending file

tar -xZf all.tar.z

In addition, for common compressed files under Window, zip and.rar, Linux also have corresponding methods to unzip them:

1) for zip

The zip and unzip programs are provided under linux. zip is the compression program and unzip is the decompression program. They have a lot of parameter options, so I will only briefly introduce them here, but I will still give an example to illustrate the usage of 1:

# zip all.zip *.jpg

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

# unzip all.zip

This command is to unzip all the files in all.zip

2) for rar

To process.rar files under linux, you need to install RAR for Linux, which you can download from the web, but remember, RAR for Linux is not free; From http: / / www. rarsoft. com/download htm download RARfor Linux 3.2.0, then install:

# tar -xzpvf rarlinux-3.2.0.tar.gz
# cd rar
# make

So you've installed it, and now you have rar and unrar, rar is the compression program, unrar is the decompression program. They have a lot of parameter options, so I will only briefly introduce them here, but I will still give an example to illustrate the usage of 1:

# rar a all *.jpg

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

# unrar e all.rar

This command is to unpack all the files in all.rar to the following. We have already introduced tar, gzip, gunzip, bzip2, bunzip2, compress, uncompress, zip, unzip, rar, unrar and other programs under linux. You should already be able to use them to unzip 10 files:.tar,.gz,.tar.gz,.tgz,.bz2,.bz2,.Z,.tar.Z,.zip,.rar. You shouldn't have to worry about downloading a piece of software and not knowing how to unzip it under Linux. And the above method is also basically effective for Unix.

This paper introduces the compression programs tar, gzip, gunzip, bzip2, bunzip2, compress, uncompress, zip, unzip, rar, unrar and unrar under linux. tar,.gz,.tar.gz,.tgz,.bz2,.Z,.tar.Z,.zip,.rar

The following supplementary

tar

-c: create compressed files
- x: decompression
-t: view the content
-r: appends a file to the end of a compressed archive
-u: update the files in the original zip

These are separate commands, and you need to use one of them to compress and uncompress, and you can use it with other commands, but you can only use one of them. The following parameters are optional when compressing or decompressing the file as needed.

-z: has the gzip property
-j: having bz2 properties
-Z: has the compress property
-v: shows all processes
-O: unzip the file to standard output

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.

This command is to type all.jpg files into a package called all.tar. -c is for 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 all.tar packages. -r means to add 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 lists all the files in the all.tar package, -t means list the files

# tar -xf all.tar

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

tar.tar *.jpg // package all the jpg files in the directory into tar. jpg

jpg // package all the jpg files in the directory into jpg.tar and then compress them with gzip to produce a package that is gzip compressed and named jpg.tar.gz

tar, tar.bz2 *.jpg // package all the jpg files in the directory into jpg.tar, and then compress them with bzip2 to produce a package with bzip2 compressed, named jpg.tar.bz2

Z *.jpg // package all the jpg files in the directory into jpg.tar and then compress them with compress to produce a package which is umcompress compressed and named jpg.tar.Z

rar a jpg. rar *.jpg //rar compression, you need to download rar for linux

zip jpg. zip *.jpg //zip compression, you need to download zip for linux

Unpack the

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

conclusion

1. *.tar unzip with tar and xvf
2. *.gz is extracted by gzip-d or gunzip
3. *.tar.gz and *.tgz are extracted with tar and xzf
4. *.bz2 can be extracted by bzip2-d or bunzip2
5. *.tar.bz2 extract with tar and xjf
6, *.Z extract with uncompress
7. *.tar.Z extract with tar and xZf
8. *.rar is extracted with unrar e
9. *.zip is extracted with unzip


Related articles: