Linux compression and decompression commands

Source: Internet
Author: User
Tags gz file
Targz decompression: tarzxvfFileNametargz compression: tarzcvfFileNametargzDirName summarizes the compression and decompression methods of various & amp; 26684; compressed packages in linux. But I didn't use some methods.

.Tar.gz

Decompress: tar zxvf FileName.tar.gz

Compression: tar zcvf FileName.tar.gz DirName

This section roughly summarizes the compression and decompression methods for various formats of compressed packages in linux. However, I have not used some of the methods. I hope you can help me with them. I will modify them at any time. thank you!

. Tar

Unpack: tar xvf FileName.tar

Package: tar cvf FileName.tar DirName

(Note: tar is packed, not compressed !)

---------------------------------------------

. Gz

Decompress 1: gunzip FileName.gz

Decompress 2: gzip-d FileName.gz

Compression: gzip FileName

.Tar.gz and. tgz

Decompress: tar zxvf FileName.tar.gz

Compression: tar zcvf FileName.tar.gz DirName

---------------------------------------------

. Bz2

Decompress 1: bzip2-d FileName.bz2

Decompress 2: bunzip2 FileName.bz2

Compression: bzip2-z FileName

.Tar.bz2

Decompress: tar jxvf FileName.tar.bz2

Compression: tar jcvf FileName.tar.bz2 DirName

---------------------------------------------

. Bz

Extract 1: bzip2-d FileName. bz

Decompress 2: bunzip2 FileName. bz

Compression: unknown

. Tar. bz

Decompress: tar jxvf FileName.tar. bz

Compression: unknown

---------------------------------------------

. Z

Decompress: uncompress FileName. Z

Compression: compress FileName

. Tar. Z

Decompress: tar Zxvf FileName.tar. Z

Compression: tar Zcvf FileName.tar. Z DirName

---------------------------------------------

. Zip

Decompress: unzip FileName.zip

Compression: zip FileName.zip DirName

---------------------------------------------

. Rar

Decompress: rar x FileName.rar

Compression: rar a FileName.rar DirName

Rar please download to: http://www.rarsoft.com/download.htm!

After decompression, copy rar_static to the/usr/bin directory (other directories specified by the $ PATH environment variable can also be used ):

[Root @ www2 tmp] # cp rar_static/usr/bin/rar

---------------------------------------------

. Lha

Decompress: lha-e FileName. lha

Compression: lha-a FileName. lha FileName

Lha please: http://www.infor.kanazawa-it.ac.jp /~ Ishii/lhaunix/download!

> After decompression, copy lha to the/usr/bin directory (other directories specified by the $ PATH environment variable can also be used ):

[Root @ www2 tmp] # cp lha/usr/bin/

---------------------------------------------

. Rpm

Unpack: rpm2cpio FileName. rpm | cpio-div

---------------------------------------------

. Deb

Unpack: ar p FileName. deb data.tar.gz | tar zxf-

---------------------------------------------

. Tar. tgz .tar.gz. tar. Z. tar. bz .tar.bz2. zip. cpio. rpm

. Deb. slp. arj. rar. ace. lha. lzh. lzx. lzs. arc. sda. sfx. lnx

. Zoo. cab. kar. cpt. pit. sit. sea

Decompress: sEx x FileName .*

Compression: sEx a FileName. * FileName

SEx only calls related programs and does not support compression or decompression. please note!

For sEx, go to http://sourceforge.net/projects/sexto download it!

After decompression, copy sEx to the/usr/bin directory (other directories specified by the $ PATH environment variable can also be used ):

[Root @ www2 tmp] # cp sEx/usr/bin/

References: Linux file compression tool Guide

(In fact, help is the best method. Generally, you can use the "-- help" parameter for each command to get a commonly used method !)

Users often need to back up data in computer systems. to save storage space, backup files are often compressed. The following describes the backup and compression tar commands respectively.

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.

Example 1: Create a full-part sub-directory file named usr.tar in the/home directory.

$ Tar cvf usr.tar/home

Example 2: Complete the sub-directories in the/home directory and compress them with the name usr.tar.gz.

$ Tar czvf usr.tar.gz/home

Example 3: restore and decompress the backup file usr.tar.gz.

$ Tar xzvf usr.tar.gz

Example 4: The contents of the usr.tar backup file are displayed on the display in split screen mode.

$ Tar tvf usr.tar | more

To back up a file to a specific device, you only need to use the device name as the backup file name.

Example 5: You can create a backup file in a floppy disk of the/dev/fd0 device and copy all the files in the/home directory to the backup file.

$ Tar cf/dev/fd0/home

To restore files on a device disk, use the xf option:

$ Tar xf/dev/fd0

If the size of the backup file exceeds the storage space available for the device, such as a floppy disk, you can create a multi-volume tar backup file. The M option indicates that the tar command prompts you to use a new storage device. when you use the M option to archive a disk drive, when a floppy disk is full, the tar command reminds you to add a new floppy disk. In this way, you can save the tar file to several disks.

$ Tar cMf/dev/fd0/home

To restore the files on several disks, you only need to put the first disk into the soft drive, and then enter the tar command with the x and M options. If necessary, you will be reminded to add another floppy disk.

$ Tar xMf/dev/fd0

Gzip command

There are two obvious advantages to reduce the file size. one is to reduce the storage space, and the other is to reduce the transmission time when the file is transmitted over the network. Gzip is a frequently used command in Linux to compress and decompress files, which is convenient and easy to use.

Syntax: gzip [option] compressed (decompressed) file name

Meaning of each option:

-C writes the output to the standard output and keeps the original file.

-D. decompress the compressed file.

-L the following fields are displayed for each compressed file:

Size of the compressed file

Size of uncompressed files

Compression ratio

Uncompressed file name

-R recursively searches for the specified directory and compresses all the files or decompress the files.

-T test to check whether the compressed file is complete.

-V displays the file name and compression ratio for each compressed and decompressed file.

-Num uses the specified numeric num to adjust the compression speed.-1 or -- fast indicates the fastest compression method (low compression ratio), and-9 or -- best indicates the slowest compression method (high compression ratio ). The default value is 6.

Assume that a directory/homehas the mm.txtw.sort.txt and xx.com files.

Example 1: compress each file in the/homecatalog into A. gz file.

$ Cd/home

$ Gzip *

$ Ls

M.txt.gz sort.txt.gz xx.com.gz

Example 2: extract each compressed file in example 1 and list the detailed information.

$ Gzip-dv *

Mm.txt.gz 43.1% ----- replaced with mm.txt

Sort.txt.gz 43.1% ----- replaced with sort.txt

Xx.com.gz 43.1% ----- replaced with xx.com

$ Ls

Mm.txt sort.txt xx.com

Example 3: Detailed information of each compressed file in Example 1 is displayed without decompression.

$ Gzip-l *

Compressed uncompr. ratio uncompressed_name

277 445 43.1% mm.txt

278 445 43.1% sort.txt

277 445 43.1% xx.com

$ Ls

Mm.txt.gz sort.txt.gz xx.com.gz

Example 4: compress a Tartar file, for example, usr.tar. the extension name of the compressed file is .tar.gz.

$ Gzip usr.tar

$ Ls

Usr.tar.gz

Unzip command

How can I expand files compressed by winzip in Microsoft Windows in Linux? You can use the unzipcommand to unexpand a compressed file named. zip.

Syntax: unzip [option] Compressed file name. zip

The meanings of each option are as follows:

-X file list: decompress the file, but does not include the specified file.

-V.

-T whether the test file is damaged, but the pressure is not solved.

-D Directory: decompress the compressed file to the specified directory.

-Z only displays the annotation of the compressed file.

-N does not overwrite existing files.

-O overwrites existing files and does not require user confirmation.

-J. do not recreate the directory structure of the document and decompress all the files to the same directory.

Example 1: extract text.zip from the current directory.

$ Unzip text.zip

Example 2: decompress the compressed file text.zip under the specified directory/tmp. if the same file already exists, the unzip command must not overwrite the original file.

$ Unzip-n text.zip-d/tmp

Example 3: view the Directory of the compressed file.

$ Unzip-v text.zip

Zgrep command

The function of this command is to find a matching regular expression in a compressed file. the usage is the same as that of the grep command, except that the object operated is a compressed file. You can use the zgrep command to check whether a certain sentence exists in a compressed file. .
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.