One linux command (32) every day: gzip command

Source: Internet
Author: User
Tags gz file touch command uncompress
One linux command every day (32): gzip command link: One linux command every day (1): ls command http://www.2cto.com/os/201210/163049.html ; One linux command every day (2): cd command http://www.2cto.com/os/201210/163050.html A linux command (32) every day: gzip command link: A linux command (1) every day: ls command http://www.2cto.com/os/201210/163049.html ; One linux command every day (2): cd command http://www.2cto.com/os/201210/163050.html ; One linux command every day (3): pwd command http://www.2cto.com/os/201210/163462.html ; One linux command every day (4): mkdir command http://www.2cto.com/os/201210/163463.html ; One linux command every day (5): rm command http://www.2cto.com/os/201210/163662.html ; One linux command (6) every day: rmdir command http://www.2cto.com/os/201210/164017.html ; One linux command (7) every day: mv command http://www.2cto.com/os/201210/164247.html ; One linux command every day (8): cp command http://www.2cto.com/os/201210/164254.html ; One linux command every day (9): touch Command http://www.2cto.com/os/201211/165699.html ; One linux command every day (10): cat command http://www.2cto.com/os/201211/165989.html ; One linux command every day (11): nl command http://www.2cto.com/os/201211/165990.html One linux command every day (12): more command http://www.2cto.com/os/201211/165994.html One linux command every day (13): less command http://www.2cto.com/os/201211/165998.html One linux command every day (14): head Command http://www.2cto.com/os/201211/166191.html One linux command every day (15): tail command http://www.2cto.com/os/201211/168702.html One linux command every day (16): which command http://www.2cto.com/os/201211/168890.html A linux command (17) every day: whereis command http://www.2cto.com/os/201211/168893.html One linux command (18) every day: locate command http://www.2cto.com/os/201211/168895.html One linux command every day (19): find command overview http://www.2cto.com/os/201211/168897.html One linux command every day (20): find command exec http://www.2cto.com/os/201211/168901.html One linux command (21) every day: find command xargs http://www.2cto.com/os/201211/168903.html A linux command (22) every day: detailed description of the parameters of the find Command http://www.2cto.com/os/201211/168912.html A linux command (23) every day: Linux directory structure http://www.2cto.com/os/201211/170430.html One linux command every day (24): Linux file type and extension http://www.2cto.com/os/201211/170431.html One linux command every day (25): Explanation of linux file attributes http://www.2cto.com/os/201211/170434.html One linux command every day (26): use SecureCRT to upload and download files http://www.2cto.com/os/201211/172022.html One linux command every day (27): linux chmod command http://www.2cto.com/os/201211/172028.html One linux command every day (28): tar command http://www.2cto.com/os/201212/172641.html One linux command (29) every day: chgrp command http://www.2cto.com/os/201212/172983.html One linux command every day (30): chown command http://www.2cto.com/os/201212/173239.html A linux command (31) every day:/etc/group file details http://www.2cto.com/os/201212/174429.html 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. Gzip can be used not only to compress large and rarely used files to save disk space, but also to form popular compressed file formats in the Linux operating system together with the tar command. According to statistics, the gzip command has 60% ~ 70% compression rate. Www.2cto.com 1. command format: gzip [parameter] [file or directory] 2. command function: gzip is a widely used compression program. after a file is compressed, its name will be added ". gz "extension. 3. command parameters:-a or -- ascii uses the ASCII text mode. -C or -- stdout or -- to-stdout outputs the compressed file to the standard output device, without changing the original file. -D or -- decompress or ---- uncompress to uncompress the compressed file. -F or -- force forcibly compresses the file. Ignore whether the file name or hard connection exists and whether the file is signed. -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: the original file name and time stamp are not saved. -N or -- name: the original file name and time stamp are saved when the file is compressed. -Q or -- quiet does not display warning information. -R or -- recursive processing: All files and subdirectories under the specified directory are processed together. -S <压缩字尾字符串> Or ---- suffix <压缩字尾字符串> Change the compressed character string. -T or -- test to test whether the compressed file is correct. -V or -- verbose displays the command execution process. -V or -- version displays version information. -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. 4. example: www.2cto.com instance 1: compress each file in the test6directory into A. gz file command: gzip * output: [root @ localhost test6] # ll Total 604 --- xr -- r -- 1 root mail 302108 11-30 linklog. log --- xr -- r -- 1 mail users 302108 11-30 log2012.log-rw-r -- 1 mail users 61 11-30 08:39 log2013.log-rw-r -- 1 root mail 0 11-30 08:39 log2014.log-rw-r -- 1 root mail 0 11-30 08:39 log2015.log-rw-r -- 1 root mail 0 11-30 08:39 log2016.log- rw-r -- r -- 1 root mail 0 11-30 log2017.log [root @ localhost test6] # gzip * [root @ localhost test6] # ll total 28 --- xr -- r -- 1 root mail 1341 11- 30 08:39 linklog.log.gz --- xr -- r -- 1 mail users 1341 11-30 08:39 log2012.log.gz-rw-r -- 1 mail users 70 11-30 08:39 log2013.log.gz-rw-r -- 1 root mail 32 11-30 08:39 log2014.log.gz-rw-r -- 1 root mail 32 11-30 08:39 log2015.log.gz-rw-r -- 1 root mail 32 11-30 0 8: 39 log2016.log.gz-rw-r -- 1 root mail 32 11-30 08:39 log2017.log.gz [root @ localhost test6] # Note: instance 2: extract each compressed file in example 1, command: gzip-dv * output: [root @ localhost test6] # ll total 28 --- xr -- r -- 1 root mail 1341 11-30 linklog.log.gz --- xr -- r -- 1 mail users 1341 11-30 log2012.log.gz-rw -r -- 1 mail users 70 11-30 08:39 log2013.log.gz-rw-r -- 1 root mail 32 11-30 08:39 log2014.log.gz-rw-r -- 1 roo T mail 32 11-30 08:39 log2015.log.gz-rw-r -- 1 root mail 32 11-30 08:39 log2016.log.gz-rw-r -- 1 root mail 32 11-30 08:39 log2017.log.gz [root @ localhost test6] # gzip-dv * linklog.log.gz: 99.6% -- replaced with login: 99.6% -- replaced with log2012.log2013.log.gz: 47.5% -- replaced with log2013.log2014.log.gz: 0.0% -- replaced with log2014.log2015.log.gz: 0.0% -- rep Laced with login: 0.0% -- replaced with log2016.log2017.log.gz: 0.0% -- replaced with log2017.log [root @ localhost test6] # ll Total 604 --- xr -- r -- 1 root mail 302108 11-30 linklog. log --- xr -- r -- 1 mail users 302108 11-30 log2012.log-rw-r -- 1 mail users 61 11-30 08:39 log2013.log-rw-r -- 1 root mail 0 11-30 08:39 log2014.log-rw-r -- 1 root mail 0 11-30 08:39 log201 5. log-rw-r -- 1 root mail 0 11-30 08:39 log2016.log-rw-r -- 1 root mail 0 11-30 08:39 log2017.log [root @ localhost test6] # note: example 3: details the information of each compressed file in example 1. the command gzip-l * output is not extracted: [root @ localhost test6] # gzip-l * compressed uncompressed ratio uncompressed_name 1341 302108 linklog. log 1341 302108 99.6% log2012.log 70 61 47.5% log2013.log 32 0 0.0% log2014.log 32 0 0.0% log2015.log 32 0 0.0% log2016.log 32 0 0.0% log2017.log 2880 604277 99.5% (totals) description: instance 4: compress a Tartar file. the extension name of the compressed file is .tar.gz. Command: gzip-r log.tar output: [root @ localhost test] # ls-al log.tar-rw-r -- 1 root 307200 11-29 17:54 log.tar [root @ localhost test] # gzip-r log.tar [root @ localhost test] # ls-al log.tar.gz-rw-r -- 1 root 1421 11-29 log.tar.gz description: example 5: recursive compression Directory command: gzip-rv test6 output: [root @ localhost test6] # ll Total 604 --- xr -- r -- 1 Root mail 302108 11-30 linklog. log --- xr -- r -- 1 mail users 302108 11-30 log2012.log-rw-r -- 1 mail users 61 11-30 08:39 log2013.log-rw-r -- 1 root mail 0 11-30 08:39 log2014.log-rw-r -- 1 root mail 0 11-30 08:39 log2015.log-rw-r -- 1 root mail 0 11-30 08:39 log2016.log- rw-r -- 1 root mail 0 11-30 08:39 log2017.log [root @ localhost test6] # cd .. [root @ localhost test] # gzip-rv tes T6test6/log2014.log: 0.0% -- replaced with test6/log2014.log.gz test6/linklog. log: 99.6% -- replaced with test6/linklog.log.gz test6/log2015.log: 0.0% -- replaced with test6/log2015.log.gz test6/log2013.log: 47.5% -- replaced with test6/log2013.log.gz test6/log2012.log: 99.6% -- replaced with test6/log2012.log.gz test6/log2017.log: 0.0% -- replaced with test6/log2017.log.gz test6/log2016.log: 0.0% -- re Placed with test6/log2016.log.gz [root @ localhost test] # cd test6 [root @ localhost test6] # ll total 28 --- xr -- r -- 1 root mail 1341 11-30 linklog.log.gz --- xr -- r -- 1 mail users 1341 11-30 log2012.log.gz-rw-r -- 1 mail users 70 11-30 08:39 log2013.log.gz-rw-r -- 1 root mail 32 11 -30 08:39 log2014.log.gz-rw-r -- 1 root mail 32 11-30 08:39 log2015.log.gz-rw-r -- 1 root mail 32 11-30 08:39 lo G2016.log.gz-rw-r -- 1 root mail 32 11-30 08:39 log2017.log.gz note: In this way, all files under test are changed *. gz, the directory still exists, but the files in the directory are changed *. gz. this is compression, which is different from packaging. Because it is a directory operation, you need to add the-r option, so that you can also perform recursion on the subdirectory. Example 6: recursively decompress the directory command: gzip-dr test6 output: [root @ localhost test6] # ll total 28 --- xr -- r -- 1 root mail 1341 11-30 linklog.log.gz --- xr -- r -- 1 mail users 1341 11-30 log2012.log.gz-rw -r -- 1 mail users 70 11-30 08:39 log2013.log.gz-rw-r -- 1 root mail 32 11-30 08:39 log2014.log.gz-rw-r -- 1 root mail 32 11-30 08:39 log2015.log.gz-rw-r -- 1 root mail 32 11-30 08:39 log2016.log.gz-rw-r -- 1 root mail 32 11-30 08:39 log2017.log.gz [root @ localhost test6] # cd .. [root @ localhost test] # gzip-dr test6 [root @ localhost test] # cd test6 [root @ localhost test6] # ll Total 604 --- xr -- r -- 1 root mail 302108 11 -30 08:39 linklog. log --- xr -- r -- 1 mail users 302108 11-30 log2012.log-rw-r -- 1 mail users 61 11-30 08:39 log2013.log-rw-r -- 1 root mail 0 11-30 08:39 log2014.log-rw-r -- 1 root mail 0 11-30 08:39 log2015.log-rw-r -- 1 root mail 0 11-30 08:39 log2016.log- rw-r -- 1 root mail 0 11-30 08:39 log2017.log [root @ localhost test6] #

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.