檔案的壓縮

  1. 壓縮檔案的副檔名
    .bz2 bzip2 程式壓縮的檔案;
    .gz gzip 程式壓縮的檔案;
    .xz xz 程式壓縮的檔案;
    .tar tar 程式只打包的資料,沒有壓縮;
    .tar.bz2 tar 程式打包的檔案,且經過 bzip2 壓縮。
    .tar.gz (.tgz) tar 程式打包的檔案,且經過 gzip 壓縮。
    .tar.xz tar 程式打包的檔案,且經過 xz 壓縮。
  2. 若沒安裝 bzip2,要先安裝。
    [root@kvm8 ~]# dnf install bzip2
    
  3. bzip2 輔助說明
    [root@kvm8 ~]# bzip2 --help
    bzip2, a block-sorting file compressor.  Version 1.0.8, 13-Jul-2019.
    
       usage: bzip2 [flags and input files in any order]
    
       -h --help           print this message
       -d --decompress     force decompression
       -z --compress       force compression
       -k --keep           keep (don't delete) input files
       -f --force          overwrite existing output files
       -t --test           test compressed file integrity
       -c --stdout         output to standard out
       -q --quiet          suppress noncritical error messages
       -v --verbose        be verbose (a 2nd -v gives more)
       -L --license        display software version & license
       -V --version        display software version & license
       -s --small          use less memory (at most 2500k)
       -1 .. -9            set block size to 100k .. 900k
       --fast              alias for -1
       --best              alias for -9
    
       If invoked as `bzip2', default action is to compress.
                  as `bunzip2',  default action is to decompress.
                  as `bzcat', default action is to decompress to stdout.
    
       If no file names are given, bzip2 compresses or decompresses
       from standard input to standard output.  You can combine
       short flags, so `-v -4' means the same as -v4 or -4v, &c.
    
    參數: 
    -d    :解壓縮 
    -z    :壓縮
    
  4. bzip2 範例
    [root@kvm8 ~]# echo test > test.txt
    [root@kvm8 ~]# ll test.*
    -rw-r--r--. 1 root root 5 Oct 30 15:59 test.txt
    [root@kvm8 ~]# bzip2 -z test.txt
    [root@kvm8 ~]# ll test*
    -rw-r--r--. 1 root root 45 Oct 30 15:59 test.txt.bz2
    [root@kvm8 ~]# bzip2 -d test.txt.bz2
    [root@kvm8 ~]# ll test*
    -rw-r--r--. 1 root root 5 Oct 30 15:59 test.txt
    
  5. gzip 輔助說明
    [root@kvm8 ~]# 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
      -k, --keep        keep (don't delete) input files
      -l, --list        list compressed file contents
      -L, --license     display software license
      -n, --no-name     do not save or restore the original name and timestamp
      -N, --name        save or restore the original name and timestamp
      -q, --quiet       suppress all warnings
      -r, --recursive   operate recursively on directories
          --rsyncable   make rsync-friendly archive
      -S, --suffix=SUF  use suffix SUF on compressed files
          --synchronous synchronous output (safer if system crashes, but slower)
      -t, --test        test compressed file integrity
      -v, --verbose     verbose mode
      -V, --version     display version number
      -1, --fast        compress faster
      -9, --best        compress better
    
    With no FILE, or when FILE is -, read standard input.
    
    Report bugs to <bug-gzip@gnu.org>.
    
    參數: 
    -d    :解壓縮 
    -# --fast --best:# 為數字,--fast 是 1 壓縮速度最快;--best 是 9 最佳壓縮比,預設是 6。
    
  6. gzip 範例
    [root@kvm8 ~]# gzip test.txt
    [root@kvm8 ~]# ll test*
    -rw-r--r--. 1 root root 34 Oct 30 15:59 test.txt.gz
    [root@kvm8 ~]# gzip -d test.txt
    [root@kvm8 ~]# ll test*
    -rw-r--r--. 1 root root 5 Oct 30 15:59 test.txt