1.ZIP命令
“.zip”是 Windows 中最常用的压缩格式,Linux 也可以正确识别“.zip”格式,这可以方便地和Windows 系统通用压缩文件。
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:将压缩数据输出到标准输出中,可以用于保留源文件
-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