檔案的打包壓縮

  1. 以 c 選項打包,j 選項用 bzip2 壓縮,將 /usr/local/bin 整個目錄打包並壓縮為 testbin.tar.bz2。
    [root@kvm8 ~]# tar jcvf testbin.tar.bz2 /usr/local/bin
    tar: Removing leading `/' from member names
    /usr/local/bin/
    /usr/local/bin/ex200
    /usr/local/bin/garmin
    [root@kvm8 ~]# ll test*
    -rw-r--r--. 1 root root 20480 Oct 30 17:07 testbin.tar
    -rw-r--r--. 1 root root  4332 Oct 30 17:11 testbin.tar.bz2
    -rw-r--r--. 1 root root 10240 Oct 30 17:07 test.tar
    -rw-r--r--. 1 root root     5 Oct 30 15:59 test.txt
    
  2. 以 c 選項打包,z 選項用 gzip 壓縮,將 /usr/local/bin 整個目錄打包並壓縮為 testbin.tgz。
    [root@kvm8 ~]# tar zcvf testbin.tgz /usr/local/bin
    tar: Removing leading `/' from member names
    /usr/local/bin/
    /usr/local/bin/ex200
    /usr/local/bin/garmin
    [root@kvm8 ~]# ll test*
    -rw-r--r--. 1 root root 20480 Oct 30 17:07 testbin.tar
    -rw-r--r--. 1 root root  4332 Oct 30 17:11 testbin.tar.bz2
    -rw-r--r--. 1 root root  4209 Oct 30 17:12 testbin.tgz
    -rw-r--r--. 1 root root 10240 Oct 30 17:07 test.tar
    -rw-r--r--. 1 root root     5 Oct 30 15:59 test.txt
    
  3. 以 c 選項打包,J 選項用 xz 壓縮,將 /usr/local/bin 整個目錄打包並壓縮為 testbin.tar.xz。
    [root@kvm8 ~]# tar Jcvf testbin.tar.xz /usr/local/bin
    tar: Removing leading `/' from member names
    /usr/local/bin/
    /usr/local/bin/ex200
    /usr/local/bin/garmin
    [root@kvm8 ~]# ll test*
    -rw-r--r--. 1 root root 20480 Oct 30 17:07 testbin.tar
    -rw-r--r--. 1 root root  4332 Oct 30 17:11 testbin.tar.bz2
    -rw-r--r--. 1 root root  3560 Oct 30 17:13 testbin.tar.xz
    -rw-r--r--. 1 root root  4209 Oct 30 17:12 testbin.tgz
    -rw-r--r--. 1 root root 10240 Oct 30 17:07 test.tar
    -rw-r--r--. 1 root root     5 Oct 30 15:59 test.txt