1、zip
压缩文件
zip 压缩文件名 压缩文件 (zip xxx.zip file)
压缩目录
zip -r 压缩文件名 压缩目录 (zip -r xxx.zip /dir)
解压缩
unzip xxx.zip(解压到当前目录)
unzip -d /dir xxx.zip(解压到指定目录 )
2、gzip(.gz格式,不能打包)
压缩
gzip file (打包file文件自动生成 file.gz ,原file将被删除)
gzip -c file >file.gz(打包file文件生成 file.gz原file将保留)
gzip -r dir (将目录下的所有文件全部压缩成.gz)
解压缩
gzip -d file.gz
gzip -dr dri(将目录下的所有已压缩的文件解缩)
3、bzip2(.bz2格式 不能压缩目录)
压缩
bzip2 -kv file (将文件压缩成file.bz2文件,参数k保留原文件,v显示压缩信息)
解压缩
bzip2 -dk file.bz2 (将文件file.bz2解压,参数k保留原压缩文件)
4、tar(只打包不压缩)
压缩
tar [选项] [-f 压缩包名] 源文件或目录
-c: 打包
-f: 指定压缩包的文件名。压缩包的扩展名是用来给管理员识别格式的,所以一定要正确指定扩展名
-v: 显示打包文件过程
如:#tar -cvf file.tar /etc
解压缩
tar [选项] 压缩包
选项:
-x: 解打包
-f: 指定压缩包的文件名
-v: 显示解打包文件过程
-t: 测试,就是不解打包,只是查看包中有哪些文件
-C(大) 目录:指定解打包位置
如:
# tar -xvf file.tar -C a/b/
5、“.tar.gz”和“.tar.bz2”格式
使用tar命令直接打包压缩。命令格式如下:
[root@localhost ~]# tar [选项] 压缩包源文件或目录
选项:
-z: 压缩和解压缩“.tar.gz”格式
-j: 压缩和解压缩“.tar.bz2”格式
例如:.tar.gz格式
[root@localhost ~]# tar -zcvf tmp.tar.gz /tmp/
#把/tmp/目录直接打包压缩为“.tar.gz”格式
[root@localhost ~]# tar -zxvf tmp.tar.gz
#解压缩与解打包“.tar.gz”格式
例如:.tar.bz2格式
[root@localhost ~]# tar -jcvf tmp.tar.bz2 /tmp/
#打包压缩为“.tar.bz2”格式,注意压缩包文件名
[root@localhost ~]# tar -jxvf tmp.tar.bz2
#解压缩与解打包“.tar.bz2”格式
再举几个例子:
[root@localhost ~]# mkdir test
[root@localhost ~]# touch test/abc
[root@localhost ~]# touch test/bcd
[root@localhost ~]# touch test/cde
#建立测试目录和测试文件
[root@localhost ~]# tar -zcvf test.tar.gz test/
#压缩
[root@localhost ~]# tar -ztvf test.tar.gz
#只查看,不解压
[root@localhost ~]# tar -zxvf test.tar.gz -C /tmp
#解压缩到指定位置
[root@localhost ~]# tar -zxvf test.tar.gz -C /tmp test/cde
#只解压压缩包中的特定文件,到指定位置
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/71260.html