Detailed description of Linux compression and decompression commands

Source: Internet
Author: User
Tags rar extension uncompress
Linux zip command

Zip-r myfile.zip ./*
Compress all files and folders in the current directory into myfile.zip files.-R indicates recursively compressing all files in the subdirectory.
2. Unzip
Unzip-o-d/home/sunny myfile.zip
Decompress the myfile.zip file to/home/sunny/
-O: overwrite the file without prompting;
-D:-D/home/sunny indicates to extract the file to the/home/sunny directory;
3. Miscellaneous
Zip-D myfile.zip smart.txt
Delete the smart.txt file from the compressed file
Zip-M myfile.zip./rpm_info.txt
Export rpm_info.txt file to myfile.zipin the compressed file
-------------------------------------------------------------------------------
To use zip to compress the file, enter the following command at the shell prompt:
Zip-r filename.zip filesdir

In this example, filename.zip represents the file you created, and filesdir represents the directory where you want to place the new zip file. The-r option specifies that you want to recursively include all files included in the filesdir directory.
To extract the content of a zip file, type the following command:
Unzip filename.zip

You can use the zip command to process multiple files and directories at the same time by listing them one by one and using the space interval:
Zip-r filename.zip file1 file2 file3/usr/work/School

The preceding command compresses the contents of the file1, file2, file3, and/usr/work/school directories (assuming this directory exists) and then stores them in the filename.zip file.
Tar command details
-C: Create a compressed file
-X: Extract
-T: View content
-R: append an object to the end of the compressed archive object
-U: update files in the original compressed package
These five are independent commands, one of which must be used for compression and decompression. They can be used with other commands, but only one of them can be used. The following parameters are optional when files are compressed or decompressed as needed.
-C: Create a compressed file
-X: Extract
-T: View content
-R: append an object to the end of the compressed archive object
-U: update files in the original compressed package
The following parameter-F is required
-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 pack all. jpg files into a package named all.tar. -C indicates that a new package is generated.-F specifies the package file name.
# Tar-RF all.tar *. gif
This command adds all .gif files to the package of all.tar. -R indicates adding files.
# Tar-UF all.tar logo.gif
This command is used to update the logo.gif file in tarbao all.tar.-u indicates that the file is updated.
# Tar-TF all.tar
This command is used to list all files in the all.tar package.-T is used to list objects.
# Tar-XF all.tar
This command is used to extract all the files in the all.tar package.
Compression
Tar-CVF jpg.tar *. jpg // pack all JPG files in the Directory into tar.jpg
Tar-CZF jpg.tar.gz *. jpg // JPG
Tar-CJF jpg.tar.bz2 *. jpg // JPG
Tar-CZF jpg.tar. z *. jpg // JPG. Z
Rar a jpg.rar *. jpg // RAR format compression, You need to download RAR for Linux
Zip jpg.zip *. jpg // ZIP format compression, You need to download zip for Linux first
Extract
Tar-xvf file.tar // decompress the tar package
Tar-xzvf file.tar.gz // decompress tar.gz
Tar-xjvf file.tar.bz2 // unzip tar.bz2
Tar-xzvf file.tar. Z // extract tar. Z
Unrar e file.rar // extract RAR
Unzip file.zip // decompress the ZIP file
Summary
1. Decompress *. tar with tar-xvf
2. Use gzip-D or gunzip to decompress *. GZ
3. Use tar-xzf to decompress * .tar.gz and *. tgz.
4. Use Bzip2-D for *. bz2 or use bunzip2 for decompression.
5. Use tar-xjf to decompress * .tar.bz2
6. Use uncompress to decompress *. Z
7. Decompress *. Tar. Z with tar-xzf
8. Extract files using unrar E for *. rar
9. Decompress *. Zip with unzip

Tar command
Tar can create files and directories. Using tar, you can create a file (backup file) for a specific file, change the file in the file, or add a new file to the file. Tar was originally used to create files on tape. Now, you can create files, such as floppy disks, on any device. Using the tar command, you can package a large number of files and directories into one file, which is very useful for backing up files or combining several files into one file for network transmission. Tar on Linux is of the GNU version.
Syntax: Tar [primary option + secondary option] file or directory
When you use this command, the main option is required, and it tells tar what to do. The auxiliary option is used for assistance and can be used.
Main options:
C. Create a new archive file. Select this option if you want to back up a directory or some files.
R: append the file to the end of the file. For example, if you have prepared a backup file and find that there is still a directory or some files have forgotten to be backed up, you can use this option to append the directory or files you have forgotten to the backup file.
T list the file content and check which files have been backed up.
U updates the file. That is to say, replace the original backup file with the new file. If the file to be updated cannot be found in the backup file, append it to the end of the backup file.
X release a file from the file.
Auxiliary options:
B. This option is set for the tape drive. It is followed by a number to describe the block size. The default value is 20 (20*512 bytes ).
F. This option is usually required when you use an archive file or device.
K. Save the existing files. For example, if we restore a file, the same file will not be overwritten during restoration.
M sets the modification time of all files to the present when restoring files.
M creates a multi-volume archive file to store it on several disks.
V detailed report on the file information processed by tar. If this option is not available, tar does not report file information.
W each step requires confirmation.
Z uses gzip to compress/decompress the file. With this option, the file can be compressed. However, you must use this option to decompress the file during restoration.
Analysis of compressed files in Linux
For those who are new to Linux, they will surely get dizzy with a bunch of various file names in Linux. For example, we know that there are only two common types of compressed files in Windows: Zip and. Rap. Examples and many other compressed file names. .zipand .rarin windows can also be used in linux, and too few people will use .zipand .rar in linux. This article will summarize these common compressed files. I hope you will not be confused when you encounter these files next time.
Before summarizing various types of compressed files, we should first clarify two concepts: Packaging and compression. Packaging refers to converting a large number of files or directories into a total file. Compression refers to converting a large file into a small file through some compression algorithms. Why do we need to differentiate these two concepts? In fact, this is because many Linux compression programs can only compress one file, so when you want to compress a large number of files, you have to use another tool to compress these files into a package and then compress the original compression program.
At the end of lifecycle. After the tar package is generated, you can use other programs to compress it. So let's first talk about the basic usage of the tar command:
There are many options for the tar command (which can be viewed using man TAR), but there are several commonly used options. The following is an example:
# Tar-CF all.tar *. jpg
This command is to pack all. jpg files into a package named all.tar. -C indicates that a new package is generated.-F specifies the package file name.
# Tar-RF all.tar *. gif
This command adds all .gif files to the package of all.tar. -R indicates adding files.
# Tar-UF all.tar logo.gif
This command is used to update the logo.gif file in tarbao all.tar.-u indicates that the file is updated.
# Tar-TF all.tar
This command is used to list all files in the all.tar package.-T is used to list objects.
# Tar-XF all.tar
This command is used to extract all the files in the all.tar package.
The above is the most basic usage of tar. To help you compress or decompress files while packing and unpackage, tar provides a special feature. This means that tar can call other compression programs, such as gzip and Bzip2, while packaging or unpacking.
1) tar calls Gzip
Gzipis a program developed by gnuorganization. The file ending with .gz is the result of gzip compression. The decompress program relative to gzip is gunzip. Use the-Z parameter in tar to call gzip. The following is an example:
# Tar-CZF all.tar.gz *. jpg
Bytes
# Tar-xzf all.tar.gz
This command unlocks the generated package.
2) tar call Bzip2
Bzip2is a more powerful compression program. The file ending with .bz2 is the result of Bzip2 compression. The decompress program relative to Bzip2 is bunzip2. Use the-J parameter in tar to call gzip. The following is an example:
# Tar-CJF all.tar.bz2 *. jpg
Bytes
# Tar-xjf all.tar.bz2
This command unlocks the generated package.
3) tar call Compress
Compress is also a compression program, but it seems that there are not as many people using compress as gzip and Bzip2 .. The file ending with Z is the result of Bzip2 compression. The decompress program relative to compress is uncompress. Use the-Z parameter in tar to call gzip. The following is an example:
# Tar-CZF all.tar. z *. jpg
Forbidden. Z
# Tar-xzf all.tar. Z
This command is used to unbind the generated package.
With the above knowledge, you should be able to uncompress a variety of compressed files. The following is a summary of the compressed files in the TAR series:
1st pair of files ending with .tar
Tar-XF all.tar
2XX for the file ending with .gz
Gzip-D all.gz
Gunzip all.gz
32.16.tgzor .tar.gz
Tar-xzf all.tar.gz
Tar-xzf all. tgz
4)for the file ending with .bz2
Bzip2-D all.bz2
Bunzip2 all.bz2
5 bytes for the file ending with tar.bz2
Tar-xjf all.tar.bz2
6) for files ending with. Z
Uncompress all. Z
72.16.tar. Z
Tar-xzf all.tar. Z
In addition, Linux has corresponding methods to decompress the compressed files .zipand .rar in Windows:
1)for. Zip
Linux provides zip and unzip programs, Zip is a compression program, and unzip is a decompression program. They have many Parameter options. Here we will only give a brief introduction and give examples to illustrate their usage:
# Zip all.zip *. jpg
This command compresses all .jpg files into a zip package.
# Unzip all.zip
This command decompress all files in all.zip.
2XX vs. .rar
To process the. rar file in linux, you need to install RAR for Linux, which can be downloaded from the Internet, but remember, rar for Linux
Not free; then install:
# Tar-xzpvf rarlinux-3.2.0.tar.gz
# Cd RAR
# Make
After installation, there will be two programs, RAR and unrar. rar is a compression program, and unrar is a decompression program. They have many Parameter options. Here we will only give a brief introduction and give examples to illustrate their usage:
# Rar a all *. jpg
This command is to compress all. jpg files into a rarpackage named all.rar. the program will automatically append the. rar extension name to the package name.
# Unrar e all.rar
This command is to extract all files from all.rar.
So far, we have already introduced tar, Gzip, gunzip, Bzip2, bunzip2, compress, uncompress, example, in Linux ,. these 10 types of compressed files, zw..tar.zw..zipw.rar, have been decompressed. In the future, you should not have to worry about downloading a software and not knowing how to unbind it in Linux. In addition, the above method is basically effective for Unix.
This article describes the compressed files tar, Gzip, gunzip, Bzip2, bunzip2, And. tgz424.bz22.16.tar.bz22.16.z2.16.tar.z2.16.zip#.rar in Linux.

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.