gzip/gunzip compress or expand files
gzip
Help
gzip [ -acdfhlLnNrtvV19 ] [-S suffix] [ name ...  ]
# gzip --help
Usage: gzip [OPTION]... [FILE]...
Compress or uncompress FILEs (by default, compress FILES in-place).
Mandatory arguments to long options are mandatory for short options too.
  -c, --stdout      write on standard output, keep original files unchanged
  -d, --decompress  decompress
  -f, --force       force overwrite of output file and compress links
  -h, --help        give this help
  -l, --list        list compressed file contents
  -L, --license     display software license
  -n, --no-name     do not save or restore the original name and time stamp
  -N, --name        save or restore the original name and time stamp
  -q, --quiet       suppress all warnings
  -r, --recursive   operate recursively on directories
  -S, --suffix=SUF  use suffix SUF on compressed files
  -t, --test        test compressed file integrity
  -v, --verbose     verbose mode
  -V, --version     display version number
  -1, --fast        compress faster
  -9, --best        compress better
    --rsyncable   Make rsync-friendly archive
With no FILE, or when FILE is -, read standard input.
Report bugs to <bug-gzip@gnu.org>.
Level | ZLIB  | GZIP
1   | 78 01 | 1F 8B
2   | 78 5E | 1F 8B
3   | 78 5E | 1F 8B
4   | 78 5E | 1F 8B
5   | 78 5E | 1F 8B
6   | 78 9C | 1F 8B
7   | 78 DA | 1F 8B
8   | 78 DA | 1F 8B
9   | 78 DA | 1F 8B
gzip 示例
# ll
total 0
-rw-r--r-- 1 root root 0 Aug 11 19:33 1.md
-rw-r--r-- 1 root root 0 Aug 11 19:33 2.md
-rw-r--r-- 1 root root 0 Aug 11 19:33 3.md
# gzip *
# ll
total 12
-rw-r--r-- 1 root root 25 Aug 11 19:33 1.md.gz
-rw-r--r-- 1 root root 25 Aug 11 19:33 2.md.gz
-rw-r--r-- 1 root root 25 Aug 11 19:33 3.md.gz
# gzip -l 1.md.gz
         compressed        uncompressed  ratio uncompressed_name
                 25                   0   0.0% 1.md
# gzip -dv *
1.md.gz:	  0.0% -- replaced with 1.md
2.md.gz:	  0.0% -- replaced with 2.md
3.md.gz:	  0.0% -- replaced with 3.md
使用 gzip 压缩 .tar 为 .tar.gz
$ tar -cvf resolv.tar /etc/resolv.conf
tar: Removing leading `/' from member names
/etc/resolv.conf
$ tar -tf resolv.tar
etc/resolv.conf
$ file resolv.tar
resolv.tar: POSIX tar archive (GNU)
# gzip 压缩,等价于 tar -zcvf resolv.tar.gz /etc/resolv.conf
$ gzip -9 < resolv.tar > resolv.tar.gz
$ file resolv.tar.gz
resolv.tar.gz: gzip compressed data, last modified: Sun Jan 21 06:41:01 2024, max compression, from Unix, original size modulo 2^32 10240
gunzip Help
gunzip [ -acfhlLnNrtvV ] [-S suffix] [ name ...  ]
# gunzip --help
Usage: /usr/bin/gunzip [OPTION]... [FILE]...
Uncompress FILEs (by default, in-place).
Mandatory arguments to long options are mandatory for short options too.
  -c, --stdout      write on standard output, keep original files unchanged
  -f, --force       force overwrite of output file and compress links
  -l, --list        list compressed file contents
  -n, --no-name     do not save or restore the original name and time stamp
  -N, --name        save or restore the original name and time stamp
  -q, --quiet       suppress all warnings
  -r, --recursive   operate recursively on directories
  -S, --suffix=SUF  use suffix SUF on compressed files
  -t, --test        test compressed file integrity
  -v, --verbose     verbose mode
      --help        display this help and exit
      --version     display version information and exit
With no FILE, or when FILE is -, read standard input.
Report bugs to <bug-gzip@gnu.org>.
gunzip 示例
# ll
total 12
-rw-r--r-- 1 root root 25 Aug 11 19:33 1.md.gz
-rw-r--r-- 1 root root 25 Aug 11 19:33 2.md.gz
-rw-r--r-- 1 root root 25 Aug 11 19:33 3.md.gz
# gunzip *
# ll
total 0
-rw-r--r-- 1 root root 0 Aug 11 19:33 1.md
-rw-r--r-- 1 root root 0 Aug 11 19:33 2.md
-rw-r--r-- 1 root root 0 Aug 11 19:33 3.md
# gzip *
# ll
total 12
-rw-r--r-- 1 root root 25 Aug 11 19:33 1.md.gz
-rw-r--r-- 1 root root 25 Aug 11 19:33 2.md.gz
-rw-r--r-- 1 root root 25 Aug 11 19:33 3.md.gz
# gzip -d *
# ll
total 0
-rw-r--r-- 1 root root 0 Aug 11 19:33 1.md
-rw-r--r-- 1 root root 0 Aug 11 19:33 2.md
-rw-r--r-- 1 root root 0 Aug 11 19:33 3.md