Compression and decompression commands under Unix

Source: Internet
Author: User
Tags unpack uncompress


. tar
Unpacking: TAR-XVF Filename.tar
Package: TAR-CVF Filename.tar DirName
(Note: Tar is packaged, not compressed!) )
. gz
Decompression 1:gunzip filename.gz
Decompression 2:gzip-d filename.gz
Compression: gzip FileName
. tar.gz
Decompression: Tar zxvf FileName.tar.gz
Compression: Tar zcvf FileName.tar.gz DirName
. bz2
Decompression 1:bzip2-d filename.bz2
Decompression 2:BUNZIP2 filename.bz2
Compression: Bzip2-z FileName
. tar.bz2
Decompression: Tar jxvf FileName.tar.bz2
Compression: Tar jcvf FileName.tar.bz2 DirName
. BZ
Decompression 1:bzip2-d
Decompression 2:BUNZIP2
Compression: Unknown
Decompression: Tar jxvf
Compression: Unknown
. Z
Decompression: uncompress filename.z
Compression: Compress FileName
. Tar. Z
Decompression: Tar zxvf filename.tar.z
Compression: Tar zcvf filename.tar.z DirName
. tgz
Decompression: Tar zxvf filename.tgz
Compression: Unknown
. tar.tgz
Decompression: Tar zxvf FileName.tar.tgz
Compression: Tar zcvf FileName.tar.tgz FileName
. zip
Decompression: Unzip
Compression: Zip DirName
. rar
Decompression: rar a Filename.rar
Compression: RAR e Filename.rar

Compression decompression
ZIP file:
Function Description: Compress the file.

Syntax: Zip [-acddffghjjkllmoqrstuvvwxyz$][-b < working directory >][-ll][-n < tail string >][-t < date time >][-< compression efficiency >][compressed file [Documents ...] [-i < template style;] [-x < template style;]

Note: Zip is a widely used compression program that compresses files that have a ". zip" extension.

-A adjusts the executable auto-unzip file.
-b< working directory > Specifies the directory where files are temporarily stored.

-C adds a comment to each compressed file.
-d deletes the specified file from within the compressed file.
The directory name is not established within the-D compressed file.
-F The effect of this parameter is similar to specifying the "-u" parameter, but not only updates the existing file, and if some files do not already exist in the compressed file, use this parameter to add it to the compressed file.
-F attempt to repair a corrupted compressed file.
-G compresses the file after it is appended to the existing compressed file, rather than creating a new compressed file.
-H online Help.
-i< template style > compress only files that match the criteria.
-j saves only the file name and its contents, not any directory names.
-J Delete unnecessary data before compressing the file.
-K uses the file name in MS-DOS compatible format.
-L When compressing a file, replace the LF character with the LF+CR character.
-ll the LF+CR character into the LF character when compressing the file.
-L displays copyright information.
-M compresses the file and joins the compressed file, deletes the original file, and then moves the file to the compressed file.
-n< string > does not compress a file with a specific trailing string.
-O to compress files that have the most recent change time in the file, set the change time for the compressed file to be the same as the file.
-Q does not show the instruction execution process.
-R recursively handles all files and subdirectories under the specified directory.
-S contains the system and hidden files.
-t< Date Time > Set the date of the compressed file to the specified date.
-T checks that each file within the backup file is correct.
-U replace the newer file into the compressed file.
-V Displays the instruction execution process or displays version information.
-V Saves the file properties of the VMS operating system.
-W in the file name if the version number, this parameter is only valid under the VMS operating system.
-x< template style > exclude files that match the criteria when compressing.
-X does not save additional file attributes.
-Y saves the symbolic connection directly, not the file that the connection points to, and this parameter is only valid under systems such as UNIX.
-Z adds a comment to the compressed file.
-$ Save the volume book name of the disk where the first compressed file is located.
-< compression Efficiency > Compression efficiency is a value between 1-9.

RAR file:

RAR usage: RAR command >-< options 1> ....-< options n> The "Action document" ... > <@ file List ... > decompression path > h/] (J k!) P x L "W:g v K q7i6v

Usually the RAR command consists of a main command plus several options (optional), which manipulate the. rar file object that the document is applied to, and the file or file list is optional for the specific file or directory that is used to implement the manipulation document.

Y0 '-o r#v R n ~ "p9f5n rar commonly used commands mainly include:

1) A add file to Operation document example rar a Test.rar file1.txt

If the Test.rar file does not exist, then package the file1.txt file into Test.rar rar a test.rar file2.txt if the Test.rar file already exists, add the File2.txt file to Test.rar (so There are two files in the Test.rar. Note that if a copy of a file is already in the action document, the A command updates the file, and the directory can also operate eg. RAR a test.rar dir1.

2) e Test.rar Note, with e decompression words, not only the original file1.txt and File2.txt is extracted to the current directory, even dir1 all the files are also extracted to the current directory, can not keep the directory structure before compression, if you want to keep the directory structure before compression, with X decompression.

3) C Add a note to the operating document, eg. RAR C Test.rar

(The reading comment from stdin appears, followed by one or more lines of comments, ending with ctrl+d).

4) CF Add file comments, similar to the above C, but this is a compressed document in each file to comment CW to write the document comments to the file eg. RAR CW Test.rar Comment.txt.

5) d Remove files from the document eg. RAR d Test.rar file1.txt E

Unzip the file to the current directory eg. rar

6) E Test.rar Note, with e decompression words, not only the original file1.txt and File2.txt is extracted to the current directory, even dir1 all the files are also extracted to the current directory, can not keep the directory structure before compression, if you want to keep the directory structure before compression, with X decompression.

7) r repair document eg. RAR R Test.rar

When there is a problem with the RAR file, you can try to repair it with this command (the ghost knows how much to use).

8) s convert document into self-extracting document eg. RAR s Test.rar

Generates a TEST.SFX executable that runs as RAR x Test.rar and is suitable for transferring files to users without RAR.

9) t test document EG. RAR T Test.rar

Detects the integrity of the Test.rar.

K) lock the document eg. RAR k Test.rar

After the document is locked, the document cannot be updated.

. Z File:
Command: Compress
Format: Compress options File list
Function: Compress file or compress standard input with Lempel-ziv compression method
Option:-R recursive operation, if you specify a directory variable, compresses all files in that directory and its subdirectories.
-C Returns the compressed data to standard output, and by default compresses the data back to the file when the file is compressed.
-V Displays the percentage of compression per folder.
Explanation: When compressing a file with compress, the extension is added after the original file name. Z. If you do not specify a file, the standard input is compressed, and the result returns standard output.
Example: Purpose: Compress/mnt/lgx/a1.doc file
Command: #compress/mnt/lgx/a1.doc
Result: The A1.doc.z file is generated after compression.

Command: uncompress
Format: uncompress options File List
Function: Extract compressed files with Compress program
Option:-c it sends compressed data to standard output instead of overwriting old compressed files
Explanation: If you do not specify a file, the standard input is decompressed. The default-C is uncompressed.
Example: Purpose: Decompression/mnt/lgx/a1.doc.z
Command: # uncompress/mnt/lgx/a1.doc.z

. gz File:

Command: gzip
Format: gzip option file directory list
Function: Compress files with Lempel-ziv encoding
Option:-C compression results are written to standard output, the original file remains unchanged. By default, gzip compresses the original file into a. gz file and deletes the original file.
-V Outputs processing information.
-D unzip the specified file.
-T tests the integrity of the compressed file.
Explanation: It is worth mentioning that gzip is more effective than compress compression.
Example: Purpose: Compress/mnt/lgx/a1.doc
Command: #gzip-v/mnt/lgx/a1.doc
Result: A compressed file that produces a1.doc.gz

Command: Gunzip
Format: Gunzip options File List
Function: Unzip files compressed with gzip command (as well as compress and zip commands)
Option:-C writes the output to standard output and the original file remains unchanged. By default, Gunzip will compress the file into an extracted file.
-L lists the files in the compressed file without being uncompressed.
-R Recursive decompression, in-depth directory structure, unzip the command line variable in the directory specified in all subdirectories of the file.
Example: Purpose: Decompression/mnt/lgx/a1.doc.gz
Command: #gunzip/mnt/lgx/a1.doc.gz

. tar file:

Command: Tar
Format: Tar options file directory list
Function: Package Backup of File directory
Option:-C to create a new archive file
-R append file to end of archive file
-X to extract files from an archive file
-O unpack the file to standard output
-V Process Output related information
-F for normal file operations
-Z Call gzip to compress the archive, and invoke gzip to complete the decompression when associated with-X
-Z Call compress to compress the archive, call compress to complete the decompression with the-X union
Example 1: To package a file in a directory with tar
Command: #tar-cvf/mnt/lgx/a1.doc
Result: produce a packaged file with an extension of. tar
Example 2: To unpack a package file with tar
Command: #tar-xvf/mnt/lgx/a1.doc.tar
Additional notes: In general, tar packaging is often used in conjunction with gzip (compression) for better results. The method is:
First packaged in tar such as: #tar-cvf/mnt/lgx/a1.doc (generates A1.doc.tar file)
Then use gzip to compress A1.doc.tar files, such as: #gzip/mnt/lgx/a1.doc.tar (Generate a1.doc.tar.gz file)
Example 3: Purpose: Unzip the a1.doc.tar.gz file
Method 1:
#gzip-dc/mnt/lgx/a1.doc.tar.gz (Generate A1.doc.tar file)
#tar-xvf/mnt/lgx/a1.doc.tar (Generate A1.doc file)
These two commands can also use the pipe function to combine two commands:
#gzip-dc/mnt/lgx/a1.doc.tar.gz | Tar-xvf
Method 2: Use tar to provide automatic call to gzip decompression function
After the tar is packaged, Compress command compression is also available (note: gzip is more efficient than compress compression), resulting in a. tar.z file that, when unpacking, can be decompressed with the "uncompress file name" format and then unpacked with "TAR-XVF file name". You can also call the "TAR-ZXVF file name" unpacking directly.

Compression and decompression commands under Unix

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: 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.