1.ZIP命令
“.zip”是 Windows 中最常用的壓縮格式,Linux 也可以正確識別“.zip”格式,這可以方便地和Windows 系統(tǒng)通用壓縮文件。
1.1.“.zip”格式的壓縮命令
[root@localhost ~]# zip [選項] 壓縮包名 源文件或源目錄
選項:
-r:壓縮目錄
例如:
[root@localhost ~]# zip ana.zip anaconda-ks.cfg
1.2.“.zip”格式的解壓縮命令
[root@localhost ~]# unzip [選項] 壓縮包名
選項:
-d:指定解壓縮位置
例如:
[root@localhost ~]# unzip -d /tmp/ ana.zip
把壓縮包解壓到指定位置
2.“.gz”格式(只壓縮,不打包)
2.1.“.gz”格式的壓縮命令
·[root@localhost ~]# gzip [選項] 源文件·
選項:
-c:將壓縮數(shù)據(jù)輸出到標(biāo)準(zhǔn)輸出中,可以用于保留源文件
-d:解壓縮
-r:壓縮目錄
[root@localhost ~]# gzip -c anaconda-ks.cfg > anaconda-ks.cfg.gz
2.2 “.gz”格式的解壓縮命令
[root@localhost ~]# gunzip install.log.gz [root@localhost ~]# gzip -d anaconda-ks.cfg.gz
3.“.bz2”格式(只打包,不能壓縮)
“.bz2”格式是 Linux 的另一種壓縮格式,從理論上來講,“.bz2”格式的算法更先進、壓縮比更好;而“.gz”格式相對來講壓縮的時間更快。
[root@localhost ~]# bzip2 [選項] 源文件
選項:
-d:解壓縮
-k:壓縮時,保留源文件
-v:顯示壓縮的詳細信息
[root@localhost ~]# bzip2 anaconda-ks.cfg
4.“.tar”格式(打包不會壓縮)
[root@localhost ~]# tar [選項] [-f 壓縮包名] 源文件或目錄
選項:
-c:打包
-f:指定壓縮包的文件名。壓縮包的擴展名是用來給管理員識別格式的,所以一定要正確指定擴展名
-v:顯示打包文件過程
5. “.tar.gz”和“.tar.bz2”格式
[root@localhost ~]# tar [選項] 壓縮包 源文件或目錄
選項:
-z:壓縮和解壓縮“.tar.gz”格式
-j:壓縮和解壓縮“.tar.bz2”格式
1.把/tmp/目錄直接打包壓縮為“.tar.gz”格式
root@localhost ~]# tar -zcvf tmp.tar.gz /tmp/
2.解壓縮與解打包“.tar.gz”格式
[root@localhost ~]# tar -zxvf tmp.tar.gz
3.解壓縮到指定位置
tar -zxvf test.tar.gz -C /tmp
4. 只解壓壓縮包中的特定文件,到指定位置
tar -zxvf test.tar.gz -C /tmp test/cde