Gzip command example

zhaozj2021-02-16  73

gzip command

Reducing the size of the file has two obvious advantages, one is to reduce the storage space, and the second is to reduce the transmission time when transmitting the file over the network. Gzip is a command to compress and decompress the files in the Linux system, which is convenient and easy to use.

Syntax: Gzip [Option] Compressed (Decompressed) file name

The meaning of each option:

-c Write the output to the standard output and retains the original file.

-d will decompress the compressed file.

-l The following fields are displayed for each compressed file:

The size of the compressed file

Uncompressed file size

Compression ratio

Name of uncompressed file

-r is classified to find all files that specify and compress them or decompress all files.

-t test, check if the compressed file is complete.

-v's file name and compression ratio for each compression and decompression file.

-num Adjusts the compressed speed, -1 or -fast represents the fastest compression method (low compression ratio), - 9 or - BEST represents the slowest compression method (high compression ratio). The system default is 6.

Suppose a directory / home has file mm.txt, sort.txt, xx.com.

Example 1: Complicates each file under the / home to the .gz file.

$ CD / Home

$ GZIP *

$ ls

m.txt.gz sort.txt.gz xx.com.gz

Example 2: Unzip each compressed file in Example 1 and lists 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 in detail information of each compressed file in Example 1, does not decompress.

$ 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 TAR backup file, such as usr.tar, at this time, the extension of the compressed file is .tar.gz

$ GZIP USR.TAR

$ ls

Usr.tar.gz

unzip command

How to expand how the compressed software under MS Windows WinZip is expanded under Linux? You can use the unzip command, which is used to desleviate the compressed file named .zip.

Syntax: unzip [option] Compressed file name .zip

The meaning of each option is:

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

-v View the compressed file directory, but does not decompress.

-t test file is damaged, but does not decompress.

-d directory solves the compressed file to the specified directory.

-z only shows the annotation of the compressed file.

-n does not override existing files.

-o covers existing files and does not require user confirmation.

-j does not rebuild the directory structure of the document, unfolding all files to the same directory.

Example 1: Unpacking the compressed file text.zip in the current directory.

$ unzip text.zip

Example 2: Repairing the compressed file text.zip Repair compression in the specified directory / TMP, if there is the same file exists, the unzip command does not overwrite the original file.

$ unzip -n text.zip -d / tmp

Example 3: View the compressed file directory, but do not decompress.

$ unzip -v text.zip

ZGREP Command The function of this command is to find a regular expression, the usage, and the GREP command, only the object of operation is a compressed file. If the user wants to see if there is a certain sentence in a compressed file, use the zgrep command.

转载请注明原文地址:https://www.9cbs.com/read-14477.html

New Post(0)