Detailed explanation and usage examples of lgzip command in Linux training tutorial

 



Not only can gzip be used to compress large, less-used files to save disk space, but it can also be used with the tar command to form a more popular compressed file format in the Linux operating system. According to statistics, the Linux training gzip command has a compression rate of 60% to 70% for text files.

  1. Command format:

  gzip[parameter][file or directory]

  2. Command function:

  gzip is a widely used compression program. After the file is compressed, its name will have an extension of ".gz".

  3. Command parameters:

  -a or --ascii Use ASCII text mode.

  -c or --stdout or --to-stdout Output the compressed file to the standard output device without changing the original file.

  -d or --decompress or ----uncompress Uncompress the compressed file.

  -f or --force Force compress files. Ignore whether the file name or hardlink exists and whether the file is a symlink.

  -h or --help Online help.

  -l or --list List information about compressed files.

  -L or --license Display version and copyright information.

  -n or --no-name When compressing a file, do not save the original file name and timestamp.

  -N or --name When compressing a file, save the original file name and timestamp.

  -q or --quiet do not display warning messages.

  -r or --recursive Recursive processing, processing all files and subdirectories in the specified directory together.

  -S<compressed suffix string> or ----suffix<compressed suffix string> Change the compressed suffix string.

  -t or --test Test that the compressed file is correct.

  -v or --verbose Display instruction execution process.

  -V or --version Display version information.

  -num Adjust the speed of compression with the specified number num, -1 or --fast means the fastest compression method (low compression ratio), -9 or --best means the slowest compression method (high compression ratio). The system default value is 6.

  4. Example of use:

  Example 1: Compress each file in the test6 directory into a .gz file

  Command :

  Copy the code as follows: gzip *

  Output:

  Copy the code as follows:

  [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 08:39 log2012.log

  -rw-r--r-- 1 mail users 61 11-30 08:39 log2013.log

  -rw-r--r-- 1 root mail 0 11-30 08:39 log2014.log

  -rw-r--r-- 1 root mail 0 11- 30 08:39 log2015.log

  -rw-r--r-- 1 root mail 0 11-30 08:39 log2016.log

  -rw-r--r-- 1 root mail 0 11-30 08:39 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--r-- 1 mail users 70 11-30 08:39 log2013.log.gz

  -rw-r--r-- 1 root mail 32 11- 30 08:39 log2014.log.gz

  -rw-r--r-- 1 root mail 32 11-30 08:39 log2015.log.gz

  -rw-r--r-- 1 root mail 32 11-30 08 :39 log2016.log.gz

  -rw-r--r-- 1 root mail 32 11-30 08:39 log2017.log.gz

  [root@localhost test6]#Example

  2: put each compressed file in Example 1 Unzip and list detailed information

  Command :

  Copy the code The code is as follows:

  gzip -dv *

  输出:

  复制代码代码如下:

  [root@localhost test6]# ll

  总计 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--r-- 1 mail users 70 11-30 08:39 log2013.log.gz

  -rw-r--r-- 1 root mail 32 11-30 08:39 log2014.log.gz

  -rw-r--r-- 1 root mail 32 11-30 08:39 log2015.log.gz

  -rw-r--r-- 1 root mail 32 11-30 08:39 log2016.log.gz

  -rw-r--r-- 1 root mail 32 11-30 08:39 log2017.log.gz

  [root@localhost test6]# gzip -dv *

  linklog.log.gz: 99.6% -- replaced with linklog.log

  log2012.log.gz: 99.6% -- replaced with log2012.log

  log2013.log.gz: 47.5% -- replaced with log2013.log

  log2014.log.gz: 0.0% -- replaced with log2014.log

  log2015.log.gz: 0.0% -- replaced with log2015.log

  log2016.log.gz: 0.0% -- replaced with log2016.log

  log2017.log.gz: 0.0% -- replaced with log2017.log

  [root@localhost test6]# ll

  总计 604

  ---xr--r-- 1 root mail 302108 11-30 08:39 linklog.log

  ---xr--r-- 1 mail users 302108 11-30 08:39 log2012.log

  -rw-r--r-- 1 mail users 61 11-30 08:39 log2013.log

  -rw-r--r-- 1 root mail 0 11-30 08:39 log2014.log

  -rw-r--r-- 1 root mail 0 11-30 08:39 log2015.log

  -rw-r--r-- 1 root mail 0 11-30 08:39 log2016.log

  -rw-r--r-- 1 root mail 0 11-30 08:39 log2017.log

  [root@localhost test6]#</p> <p>

  Example 3: Detailed display of each compressed file in Example 1 Information, do not decompress

  Command :

  Copy the code as follows: gzip -l *

  Output:

  Copy the code as follows:

  [root@localhost test6]# gzip -l *

  compressed uncompressed ratio uncompressed_name

  1341 302108 99.6% 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)

  Example 4: Compress a tar Back up the file, the extension of the compressed file is .tar.gz

  Command:

  Copy the code The code is as follows: gzip -r log.tar

  Output:

  Copy the code The code is as follows:

  [root@localhost test]# ls -al log.tar

  -rw-r--r-- 1 root 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--r-- 1 root root 1421 11-29 17:54 log.tar.gz

  Example 5: Recursive compressed directory

  Command :

  Copy the code The code is as follows :

  gzip -rv test6

  output:

  copy code The code is as follows:

  [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 08:39 log2012.log

  -rw-r--r-- 1 mail users 61 11-30 08:39 log2013.log

  -rw-r--r-- 1 root mail 0 11-30 08:39 log2014.log

  -rw-r--r-- 1 root mail 0 11-30 08:39 log2015.log

  -rw-r--r-- 1 root mail 0 11-30 08:39 log2016.log

  -rw-r--r-- 1 root mail 0 11-30 08:39 log2017.log

  [root@localhost test6]# cd ..

  [root@localhost test]# gzip -rv test6

  test6/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% -- replaced with test6/log2016.log.gz

  [root@localhost test]# cd test6

  [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--r-- 1 mail users 70 11-30 08:39 log2013.log.gz

  -rw-r--r-- 1 root mail 32 11-30 08: 39 log2014.log.gz

  -rw-r--r-- 1 root mail 32 11-30 08:39 log2015.log.gz

  -rw-r--r-- 1 root mail 32 11-30 08:39 log2016 .log.gz

  -rw-r--r-- 1 root mail 32 11-30 08:39 log2017.log.gz

  Description: In

  this way, all files under test become *.gz, and the directory still exists, just the directory The files inside accordingly become *.gz. This is compression, which is different from packaging. Because it is a directory operation, the -r option needs to be added, so that subdirectories can also be recursed.

  Example 6: Decompress a directory recursively

  Command :

  Copy the code The code is as follows:

  gzip -dr test6

  Output:

  Copy the code The code is as follows:

  [root@localhost test6]# ll

  总计 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--r-- 1 mail users 70 11-30 08:39 log2013.log.gz

  -rw-r--r-- 1 root mail 32 11-30 08:39 log2014.log.gz

  -rw-r--r-- 1 root mail 32 11-30 08:39 log2015.log.gz

  -rw-r--r-- 1 root mail 32 11-30 08:39 log2016.log.gz

  -rw-r--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

  总计 604

  ---xr--r-- 1 root mail 302108 11-30 08:39 linklog.log

  ---xr--r-- 1 mail users 302108 11-30 08:39 log2012.log

  -rw-r--r-- 1 mail users 61 11-30 08:39 log2013.log

  -rw-r--r-- 1 root mail 0 11-30 08:39 log2014.log

  -rw-r--r-- 1 root mail 0 11-30 08:39 log2015.log

  -rw-r--r-- 1 root mail 0 11-30 08:39 log2016.log

  -rw-r--r-- 1 root mail 0 11-30 08:39 log2017.log

  [root@localhost test6]#</p> <p>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326427665&siteId=291194637