zip压缩工具 tar打包 打包并压缩
- 6.5 zip压缩工具
- 6.6 tar打包
- 6.7 打包并压缩
-
zip压缩工具
xz,bzip2,gzip都不支持压缩目录
zip可以压缩目录
压缩文件
zip 2.txt.zip 2.txt
[root@localhost ~]# zip 2.txt.zip 2.txt
adding: 2.txt (deflated 99%)
[root@localhost ~]# du -sh *
108K 2.txt
4.0K 2.txt.zip
压缩目录+文件
zip -r test.zip 2.txt test/
[root@localhost ~]# zip -r test.zip 3.txt test/
解压文件
unzip test.zip
指定解压到某个目录
[root@localhost ~]# unzip 2.txt.zip -d /tmp
Archive: 2.txt.zip
inflating: /tmp/2.txt
解压的时候,不能指定解压后的文件名称
如果指定了,就会先创建指定的文件名
[root@localhost ~]# unzip 2.zip -d /1.txt
Archive: 2.zip
inflating: /1.txt/2.txt
creating: /1.txt/2/
查看文件列表,但是不可以查看文件内容
unzip -l 2.zip
-
tar打包
小提示:
求实际传输带宽:
1M = 8 M/s
100M / 8m/s=12.5M/s
tar打包工具
可以打包文件、目录、文件和目录一起,类似zip
打包:
tar -cvf xiaobo.tar xiaobo/
c create创建
v view 可视化看到过程
f 打包成的文件名
[root@localhost ~]# tar -cvf xiaobo.tar xiaobo/
xiaobo/
xiaobo/2/
xiaobo/2.txt
xiaobo/2.txt.zip
xiaobo/2.zip
xiaobo/3.txt
xiaobo/anaconda-ks.cfg
xiaobo/test.zip
[root@localhost ~]#
如果原来的tar包存在,再打包相同的文件打包名的话 就会默认覆盖!
解包:
tar -xvf xiaobo.tar
解包后会默认覆盖已经存在的文件
查看压缩包里面的文件列表
tar -tf xiaobo.tar
过滤指定的文件,不去打包该文件:
不打包xiaobo目录下的2.txt的文件
tar -cvf xiaobo.tar --exclude 2.txt xiaobo/
[root@localhost ~]# tar -cvf xiaobo.tar --exclude 2.txt xiaobo/
xiaobo/
xiaobo/2/
xiaobo/2.txt.zip
xiaobo/2.zip
xiaobo/3.txt
xiaobo/anaconda-ks.cfg
xiaobo/test.zip
[root@localhost ~]#
可以过滤多个文件:
过滤掉 txt文件类型的,过滤掉 zip文件类型的
tar -cvf xiaobo.tar --exclude "*.txt" --exclude "*.zip" xiaobo/
[root@localhost ~]# tar -cvf xiaobo.tar --exclude "*.txt" --exclude "*.zip" xiaobo/
xiaobo/
xiaobo/2/
xiaobo/anaconda-ks.cfg
[root@localhost ~]#
打包并压缩:
支持(zip)的用 czvf
tar -czvf xiaobo.tar.gz xiaobo/
支持(bzip2)的用 j
tar -cjvf xiaobo.tar.bz2 xiaobo/
支持(xz)的用 J
tar -cJvf xiaobo.tar.xz xiaobo/
解压:
(zip)
tar -zxvf xiaobo.tar.gz
(bzip2)
tar -jxvf xiaobo.tar.bz2
(xz)
tar -Jxvf xiaobo.tar.xz
查看压缩包里面的文件列表
tar -tf xiaobo.tar
tar -tf xiaobo.tar.gz
tar -tf xiaobo.bz2
tar -tf xiaobo.tar.xz

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探