Linux 下的檔案壓縮常用的格式有 tar.gz 和 tar.bz2 等,最近有接觸到的是 tar.xz 格式,會注意到 xz 格式是因為 Linux Kernel 是用 xz 壓縮格式。
壓縮
tar.gz
# tar cvzf /tmp/httpd_conf.tar.gz /etc/httpd
tar.bz2
# tar cvjf /tmp/httpd_conf.tar.bz2 /etc/httpd
tar.xz
# tar cvJf /tmp/httpd_conf.tar.xz /etc/httpd
解壓縮
tar.gz
# tar xvzf /tmp/httpd_conf.tar.gz
tar.bz2
# tar xvjf /tmp/httpd_conf.tar.bz2
tar.xz
# tar xvJf /tmp/httpd_conf.tar.xz
檔案的壓縮大小
# ls -l /tmp/httpd_conf.tar.*
-rw-r–r–. 1 root root 20692 2013-10-28 12:38 /tmp/httpd_conf.tar.bz2
-rw-r–r–. 1 root root 22494 2013-10-28 12:38 /tmp/httpd_conf.tar.gz
-rw-r–r–. 1 root root 20516 2013-10-28 12:38 /tmp/httpd_conf.tar.xz
看起來是 xz 的壓縮效果最好,其次是 tar.bz2,再其次是 tar.gz