Linux compression commands

Source: Internet
Author: User
Tags bz2 rar unpack uncompress

Tar

This is a very popular and powerful command under Linux, which retains the original file by default during compression.

Format: tar [main option + secondary option] File_or_dir

• Main option, only one of the following can occur

-C Create a new profile. Select this option if the user wants to back up a directory or some files. Equivalent to packaging.

-X releases the file from the archive file. Equivalent to unpacking.

-T lists the contents of the archive to see which files have been backed up.

• Secondary Options

-Z: Do you have the properties of gzip at the same time? i.e. do I need to compress or decompress with gzip? The general format is xx.tar.gz or XX. tgz

-Z: Do you have compress properties at the same time? i.e. do I need to compress or decompress with compress? The general format is Xx.tar.z

-j: Do you have bzip2 properties at the same time? i.e. do I need to compress or decompress with bzip2? The general format is xx.tar.bz2

-V: File details are displayed during compression!

-F: Use the file name, please note, after F to immediately answer the file name Oh! Don't add any more parameters!

-P: Use original file properties (attributes are not changed according to user)

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

. Tar (tar is archived (or packaged) without the effect of compression,. tar files are archive files )

Package: TAR-CVF File_name.tar File_or_dir

Solution: TAR-XVF file_name.tar files in the current directory

———————————————

. tar.gz and. tgz

Compression: TAR-ZCVF file_name.tar.gz File_or_dir

Decompression: TAR-ZXVF file_name.tar.gz

———————————————

. tar.bz2

Compression: TAR-JCVF file_name.tar.bz2 File_or_dir

Decompression: TAR-JXVF file_name.tar.bz2

———————————————

. Tar. Z

Compression: TAR-ZCVF file_name.tar.z File_or_dir

Decompression: TAR-ZXVF File_name.tar.z

Gzip and Gunzip

Gzip is a widely used compression command, Gunzip is its corresponding decompression command. They replace the original file directly. In fact Gunzip is only gzip hard connection, all operations can be done with gzip,file after gzip compression for file.gz.

gzip Format:gzip [parameter] file_or_dir

The parameters are as follows, and the red font indicates common parameters:

-A or--ascii: use ASCII text mode;

-D or--decompress or----uncompress: unpack the compressed file;

-F or--force: Forcibly compress the file. Ignores the existence of a file name or a hard connection and whether the file is a symbolic connection;

-H or--help: online help;

-L or--list: Lists information about compressed files;

-L or--license: Displays version and copyright information;

-N or--no-name: When compressing a file, the original file name and time stamp are not saved;

-N or--name: When compressing the file, save the original file name and time stamp;

-Q or--quiet: No warning message is displayed;

-R or--recursive: recursively handles all files and subdirectories under the specified directory;

-s< compressed Tail string > or--suffix< compressed Word tail string;: Change compressed word tail string;

-T or--test: Test whether the compressed file is correct;

-V or--verbose: Displays the instruction execution process;

-V or--version: Displays version information;

-< compression efficiency;: Compression efficiency is a value between 1~9, the default value is "6", specifying the larger the value, the higher the compression efficiency;

--best: The effect of this parameter is the same as specifying the "-9" parameter;

--fast: The effect of this parameter is the same as specifying the "-1" parameter.

gunzip Format:gunzip [parameter] file.gz

The parameters are as follows, and the red font indicates common parameters:

-A or--ascii: use ASCII text mode;

-C or--stdout or--to-stdout: Output the extracted file to the standard output device;

-F or--force: Forcibly unpack the compressed file, ignoring the existence of the file name or hard connection and whether the file is a symbolic connection;

-H or--help: online help;

-L or--list: Lists information about compressed files;

-L or--license: Displays version and copyright information;

-N or--no-name: When decompressed, if the compressed file contains the original file name and time stamp, it will ignore the processing;

-N or--name: When decompressed, if the compressed file contains the original file name and time stamp, it will be stored back to the unpacked file;

-Q or--quiet: No warning message is displayed;

-R or--recursive: recursively handles all files and subdirectories under the specified directory;

-s< compressed Tail string > or--suffix< compressed Word tail string;: Change compressed word tail string;

-T or--test: Test whether the compressed file is correct;

-V or--verbose: Displays the instruction execution process;

-V or--version: Displays version information.

Bzip2 and BUNZIP2

Obviously, bzip2 is used for compression, BUNZIP2 for decompression, and they replace the original file directly. Of course bzip2 can also be decompressed. Compressed file is file.bz2, their parameters are the same (one-D), so only list bzip2.

bzip2 Format:bzip2 [parameter] [file]

The parameters are as follows, and the red font indicates common parameters:

-C: The compression or decompression results are sent to the standard output, if the output to the screen is garbled
-D: Unzip the file with the BUNZIP2 filename. bz2
-F: Force overwrite when file with the same name
-K: After decompression, the original compressed file is not deleted and is deleted by default
-Q: Quiet mode, no output on the screen
-S: Reduces the amount of memory used when decompressing, but time increases
-T: Test the decompression effect and delete the unpacked file after testing
-V: Lists detailed information
-Z: Forced compression
-V OR-L: Displays version information

Compress and Uncompress

This can not be found in the new version of Linux ... They are basically the same as bzip2 and BUNZIP2, except that they support recursive/compressed directories, and their compressed file suffix is. Z, the Compress parameter is as follows:

• Format:compress [parameters] [File_or_dir]

The parameters are as follows, and the red font indicates common parameters:

-B: Specify the compression scale, the larger the value between 6~9, the smaller the file, but the more time it takes to compress
-C: Retains the original file after compression, but does not retain it by default
-D: Unzip the file
-F: Force compressed files
-R: Recursive compression directory and the following files
-V: Shows the full compression process
-V: Display version information

The example is simple enough to say.

Zip and Unzip

This is a particularly extensive compression format, with a file suffix of. zip, and the default retention of the original file, which is also particularly widely used:

zip Format:zip [parameter] file.zip file_or_dir

The parameters are as follows, and the red font indicates common parameters:

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

Unzip format:unzip [parameter] file.zip

The parameters are as follows, and the red font indicates common parameters:

-C Displays the extracted results to the screen and converts the characters appropriately.

-F Updates an existing file.

-L Displays the files contained within the compressed file.

-P, similar to the-c parameter, displays the results of the decompression to the screen, but does not perform any conversions.

-T checks whether the compressed file is correct, but does not understand the pressure.

-U is similar to the-f parameter, but in addition to updating existing files, other files in the compressed file are extracted to the directory.

-V displays detailed information when executed. or view the compressed files directory, but do not press.

-Z Displays only the memo text of the compressed file.

-A necessary character conversion for the text file.

-B Do not convert the text file to character.

The file names in the-C compressed file are case sensitive.

-J does not handle directory paths that are contained in compressed files.

-L Changes all the file names in the compressed file to lowercase.

-M sends the output to the more program processing.

-N Do not overwrite the original file when extracting.

-O do not need to ask the user first, unzip overwrite the original file after execution.

-p< password > password using zip option.

-Q does not display any information when executing.

-S converts white space characters in the file name to baseline characters.

-V retains the file version information for the VMS.

-X Unzip while the original uid/gid of the file is stored back.

-d< directory > Specifies the directory to be stored after the file has been decompressed.

-x< file > Specifies which files in the. zip archive are not processed.

-Z unzip-z equals execute zipinfo instruction.

rar

RAR commands and options are too many, here only some of the commonly used, compressed file suffix. rar, the default is to keep the original file .

rar format:rar [command] [options]

The commands are:

A: Add file to Operation document, example: RAR a test.rar file1.txt if Test.rar file does not exist, then package file1.txt file into Test.rar, example: rar a test.rar file2.txt If the Test.rar file already exists, add the File2.txt file to Test.rar so that there are two files in the Test.rar.

D: Delete files from the document, for example: RAR d test.rar file1.txt

E: Unzip the file to the current directory, for example: RAR e Test.rar with E decompression, not only the original file1.txt is extracted to the current directory, even dir1 inside all the files are also extracted to the current directory, can not maintain the directory structure before compression

K: Lock document, example: RAR k Test.rar when the document is locked, the document cannot be updated.

R: Repair Document, example: RAR R Test.rar

S: Convert the document into a self-extracting document, for example: RAR s Test.rar, will generate a TEST.SFX executable document, the effect of running it is equivalent to RAR x Test.rar, suitable for users without RAR file transfer

T: Test document, for example: RAR t Test.rar, detect the integrity of the test.rar, generally compressed large files ready to transfer before the best use of this command to ensure the correctness of the file

X: Extract the contents of the document with the path to the current directory, for example: rar x Test.rar, so decompression, Dir1 will keep the original directory structure

Options are:

CL: Convert file name to lowercase, cu: Convert file name to uppercase, example: RAR a-cl test.rar file.txt,file.txt becomes file.txt after adding Test.rar

DF: Delete source file After document operation, example: RAR a-df test.rar file1.txt file2.txt dir1, after compressing file1.txt,file2.txt,dir1 into Test.rar, delete source file

Ed: Do not add empty directory, example: RAR a-ed test.rar dir1, add Dir1 to Test.rar, do not operate empty directory, RAR e-ed Test.rar, extract test.rar, do not generate empty directory

k: Lock file, example: RAR a-k test.rar file1.txt, equivalent to rar a test.rar file1.txt rar k Test.rar

M<0..5>: Set compression ratio level (0-storage, 3-default, 5-MAX), example: RAR a-m0 test.rar dir1 dir2

o+: Overwrite existing files, o do not overwrite existing files, for example: RAR x-o-Test.rar, extract test.rar files, but if encountered with the existing file does not overwrite

P[password]: Set Password, example: rar a test.rar *.txt-p prettygirl compressed file Set password for prettygirl, decompression without password can not operate, if you feel that the password is too exposed, you can use RAR a Test.rar *.txt-p, the RAR program will ask you what password you want to use, do not echo

T: After compression completed integrity test, for example: rar a test.rar/home-t, after the compression test, if there is a problem error.

x<file>: Exclude specific files, for example: rar x test.rar-x *.txt, extract documents except *.txt in Test.rar

Y: All actions are answered yes, for example, sometimes when extracting the same file every time you ask whether to overwrite (y/n), plus-y can choose Yes by default, no longer ask

Linux compression commands

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.