Common Linux compression and decompression commands

Source: Internet
Author: User
Tags uncompress

LinuxCommon compression and decompression commands are shown in Table 2-5.

Table 2-5 common Linux compression and decompression commands

Common commands

Brief Chinese description

Program directory

Gzip

You can use the-d option to decompress a compressed file named. gz)

/Bin

Gunzip

Decompress the. gz compressed file with gzip and the-d parameter)

/Bin

Tar

You can also use the-z option to call gzip to compress or decompress the. gz file)

/Bin

Compress

You can use the-d option to decompress a compressed file named. Z)

/Usr/bin

Uncompress

Decompress the. Z compressed file and use the "-d" option in place of compress)

/Usr/bin

Zip

The file packaged and compressed into a file named. zip does not have the ability to decompress it. You must decompress it using unzip)

/Usr/bin

Unzip

Decompress the. zip file

/Usr/bin

Bzip2

To decompress a compressed file named. bz2, you can use the-d option to decompress it)

/Bin

Bunzip2

Decompress the. bz2 compressed file and use the bzip2 and-d options instead)

/Bin

Gzip [-Option] [file name]

Compressed into a compressed file named. gz

If you see. gz, .tar.gz files, they are the masterpiece of gzip compression.

Gzip is a type of compression program developed by the GNU organization. It is not the same as the ZIP program on Windows. We will introduce it later ).

First, we will introduce the compression method. When we have a file named big1.bmp, the file size is usually very large and gzip is used for compression. What should we do with the command?

The simplest way is as follows:

Gzip big1.bmp

But if you want it to compress the "smallest file", add the-9 option:

Gzip-9 big1.bmp

Of course, the "minimum file" cost is to take the longest time to compress. If you want it to compress well at the fastest time without worrying about the compression ratio, the opposite is true, add a-1 note, which is a number, not lower-case English l) option:

Gzip-1 big1.bmp

If you do not add-1 or-9, the default value is-6.

In addition, common options include:

The progress is displayed during the l-v compression process.

L-r compresses all the files in the subdirectory.

As for its decompression options, we deliberately moved it to the next command and explained it again.

Gunzip [-Option] ghost file name .gz]

Decompress the. gz compressed file

Compared with the gzip command, the gunzip command is used to decompress the. gz file compressed by gzip. If you have compressed files, such as big1.gz, You can decompress the files:

Gunzip big1.gz

This command can also be completed by using gzip, with the same effect:

Gzip-d big1.gz

In fact, in some versions of Linux, gunzip calls gzip. By the way, you can add a-d option and use the link file for it )! However, some versions are not real programs. However, whether gunzip is a real program or a connection, it is not important. Because the gzip program can be used for compression, decompression, and dual-use. This is not necessarily the case for each compression and decompression program .) Therefore, if you remember the-d option, you do not need to remember the gunzip command.

Gunzip can even decompress other compression programs such as Compress or ZIP files. However, we do not recommend that you do this, which will make yourself messy. In addition, it admitted that not every situation can be used to decode zip files. So now, why bother? Which of the following tools can be used for fixed purposes? Isn't it well organized and easy to remember?

Gunzip has the following options:

L-f if a file with the same name exists during decompression, the file will be overwritten without further inquiry.

L-r decompress all the files in the subdirectory.

L-v shows the progress during decompression.

These options can also be added to gzip-d, with the same effect.

Tar [-Option] [package file name] [file]

Package or unbind a. tar package

If you have carefully tried gzip, or have experience using DOS, Windows ARJ, and ZIP programs, you will find that gzip has a fatal drawback: it can only compress one file. Even for subdirectory compression, it also compresses individual files in the subdirectory, and does not compress them into a tight "package ".

Therefore, in Linux, the "package" task is used by the tar program. Note that tar is not a compression program, because it is the same size as the original package. Therefore, it is not a package program, but a package program. We are used to first package and generate a. tar file, and then compress the package .. This is the name of the tar.gz file.

Some people think that the name .tar.gz is too long. In fact, the name is. tgz, which means the same.

Tar has up to 53 options. You can see it with man tar.) But there are not so many practical applications, and they are used repeatedly every day. Therefore, we will give an example:

Tar-cf new1.tar my1 *. doc

Pack all my1 *. doc files into a new1.tar file. Among them,-c is to generate a new file;-f is to output to the default device, you can regard it as an option that must be added.

Tar-rf new1.tar my2 *. doc

New1.tar is an existing package file. We will package all the files in my2 *. doc. -R indicates adding a file.

Tar-uf new1.tar my18.doc

Only my1 *. doc has been packaged in, But my18.doc has been modified later. We will repackage the modified files, and-u will be updated.

If you have used the ARJ program, it may be a bit stupid. Because the ARJ program is similar to the preceding three processes, you only need to use the option to operate them, right? If you have never used ARJ, continue to read it.

Tar-tf new1.tar

List which files are packaged in new1.tar. -T indicates a list. This option is similar to the l option of the ARJ program.

Tar-xf new1.tar

Unpack all the files in the new1.tar package, and-x is used to unbind them.

Tar-xf new1.tar my2 *. doc

Only remove all my2 *. doc files in the new1.tar package file, and unbind-x. This option is similar to the x option of the ARJ program.

Have you noticed this? It is also similar to the ARJ program. It can be packaged or unzipped without another unzipped program. The difference between it and ARJ is once again, that is, there is no compression capability!

However, I can borrow from the gzip program! Just like although there is no bakery in a convenience store, you can sell bread on your behalf! It is the same for consumers. -The z option is the secret purchase pipeline!

Tar-zcf new1.tar.gz my1 *. doc

Note the difference between this command and a similar command. First, with the z option added, it will borrow the compression capability from gzip; second, note that the generated file name is new1.tar.gz. The two processes are completed at one time!

If you want to Compress the program later, Compress another. tar. Z file, you only need to change the-z option to the-Z option.

Tar-Zcf new1.tar. Z my1 *. doc

Finally, we add the option-v to package, compress, or decompress the package. Therefore, the most common decompression procedure is as follows:SoftwareThe packaging file is the .tar.gz file ):

Tar-zxvf onepackage.tar.gz

If it is. tgz, the file name is the same, because the nature is the same, but the file name is simpler:

Tar-zxvf onepackage. tgz

This-zxvf option is almost fixed and worth your consideration. How was this file originally generated? You can also back it up so that you can easily create your own .tar.gz file ):

Tar-zcvf onepackage.tar.gz *.*

Or

Tar-zcvf onepackage. tgz *.*

Compress [-Option] [file name]

Compressed into a compressed file named. Z

Compress is similar to gzip and is a compression and decompression tool. If you see. Z. Tar. Z files, they are the masterpiece of compress program compression.

First, we will introduce the compression method. Suppose we have a glyph file named taipei24.pcf, which is usually very large. How can we use the compress command to compress it?

The simplest is:

Compress taipei24.pcf

It will generate a taipei24.pcf. Z compressed file.

In addition, common options include:

The l-v compression process shows the progress and proportion.

As for its decompression options, we deliberately moved it to the next command uncompress.

Uncompress [-Option] [file name. Z]

Decompress the. Z compressed file

The uncompress command is opposite to the compress command, which is used to decompress the. Z file compressed by compress. If you have compressed files, such as one. Z, you can use

Uncompress one. Z

You can also use compress to complete the task, with the same effect:

Compress-d one. Z

In most versions of Linux, uncompress actually only calls compress. By the way, you can add a-d option and use the link file to do it), which is not a real program.

The compress program can be used for compression, decompression, and dual-use. This is not necessarily the case for each compression and decompression program .) Therefore, if you remember the-d option, you do not need to remember the uncompress command.

Uncompress generally uses one of the following options:

-V shows the progress during the decompression process.

Similarly, these options can be added to compress-d, with the same effect.

Zip [-Option] ghost file name. zip] [file name]

Package and compress it into a file named. zip

The difference between zip and gzip is only one letter, but the usage is much worse.

The zip format is exactly the same as the. zip format on DOS and Windows! That is to say, it can generate a "compressed file package" with two effects without going through the packaging and compression procedures ". In addition, if this format is used, you can freely access files like. bmp,. jpg,. gif, and so on between Windows and Linux! For example, you can use the WinZip program in Windows or press WinZip into. zip for Linux.

Since it is so good, why do we not use it frequently? Don't ask me. I don't know either. In the world of computers, there is often a strange phenomenon. Good things are not used by everyone. What everyone is using is often not the best choice, or they are just used by their predecessors, he used it like this.

In short, if you think that what you are not using is not good, it is likely to be wrong. At the end, find someone to analyze why things like XX were used? What are the advantages? "Universal "! It can also be one of the advantages, strange!

The zip package and compression commands are as follows ):

Zip new1.zip my1 *. doc

Pack all my1 *. doc files into a new1.zip file. New1.zip can omit the extension to new1, which defaults to the extension of. zip.

Zip-d new1.zip my18.doc

If my18.doc is a file compressed in new1.zip at the beginning, this command will extract it from the compressed file and delete it. -D Indicates deletion.

Zip-g new1.zip my32.doc

If my32.doc is not compressed in new1.zip, add it now. The-g option is to add a group rather than generate a new one. When it grows up, this letter is used more specifically ).

Zip-u new1.zip my2 *. doc

If my2 *. all the doc files have been compressed into new1.zip, but then my2 *. there are several files in the doc that have been changed, and you don't want to find out which files have changed. This Command requires the system to help you check whether the changed files have been updated to compression. Otherwise, you do not need to change the file. -U indicates the update.

Zip-r new2.zip mydir

If mydir is a directory name, it will compress all the files in the entire directory into a new2.zip file. The-r option is used to compress sub-directories.

What about the decompression options? Sorry, the zip file can only be compressed, and there is no part-time decompression function. Use unzip to decompress the package.

Unzip [-Option] ghost file name. Zip] [file name]

Decompress the. zip file

Zip and unzip are really partners. The zip program itself does not have the ability to decompress the package. You must use the unzip program to decompress the package. Unzip is a real program and is not a substitute for zip.

Because the zip program will compress a large number of files together, and during decompression, some of these files may already exist. If they do not exist, of course they are quite simple ), as a result, some complicated and tangled pressure relief situations have emerged. You have to be prepared! For example, do we need to overwrite the existing files unconditionally, or do we have to overwrite the existing files before they are new? Or, whether it is new or old, only files that do not exist can be compressed and added, or every time an existing file exists, you have to ask me, I will decide? Is there a UNIX or DOS discriminant rule? That is to say, if a compressed file contains an upper-case MYFILE, is it a file with the same name as an existing lower-case myfile or a file with different names?

Also, because zip can compress the entire sub-directory, there will be an inevitable choice during decompression: You need to decompress it back to the same location as the original directory, or decompress the existing Directory and generate a directory?

Because the above situation is too complex, we only list one sample command, and then the other options are listed directly:

Unzip onepackage.zip a *. doc

Decompress all a *. doc files in onepackage.zip. If the *. docfile name is not input, the onepackage.zip file will be decompressed. However, it is best to use the following options to determine the eight Processing decisions when you encounter an existing file name with the same name:

-F only decompress and update existing files. If other files are not pressed, you will be asked one by one when updating them ).

-U decompress and update the existing files, and decompress the files that do not exist. However, you will be asked one by one when updating the files ).

-Fo only decompress and update existing files. Other files do not have pressure, but do not ask to directly overwrite the updates ).

-Uo decompress and update an existing file, and decompress the existing file without asking to directly overwrite the update ).

-O whether the file is new or old, it will be extracted from the compressed file and overwritten directly.

-N: only extract nonexistent files. Existing files are retained regardless of the old and new files.

-C, regardless of Case sensitivity, is regarded as the same file name by default ).

-L all files are converted to lowercase letters during decompression.

In addition, Processing decisions when sub-directories exist:

-J no matter what the original directory is compressed, it is all unlocked in the current directory.

-D is followed by a directory name. You can specify to decompress the package to this directory.

One of the other common options:

-L only lists the files in the compressed package, and does not actually uncompress the package.

Bzip2 [-Option] [file name]

Compressed into a compressed file named. bz2

Bzip2 is a new generation of compression programs, but it still cannot be replaced by the old gzip BUG: only one file can be compressed. To package bzip2, you have to rely on tar for help. So you will still see files like tar.bz2.

Bzip2 references a text compression algorithm called Burrows-Wheeler block sorting and the famous Hoffman coding method Huffman coding. Therefore, the name starts with B. This compression method uses a memory unit called block during the compression process. You can customize the memory unit size of this block. The larger the block usage, the better the compression effect, of course, more memory is used. We can specify 1 ~ The memory algorithm used is as follows.

Compression:

Memory usage = 400KB + (block Size × 7)

Block size = option × 100KB

During decompression:

Memory usage = 400KB + (block Size × 4)

The size of the block during decompression is determined by the compression, so it is not determined by the option. Therefore, the following command can be issued during compression:

Bzip2-9-k myfile.doc

Compress the myfile.doc command to the smallest file. The-9 option is the default one. Upload the myfile.doc.bz2 file. The-k option indicates that although myfile.doc.bz2 is generated, the original file myfile.doc is still retained. This is what the gzip program cannot do.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.