6.5 zip压缩工具
6.6 tar打包
6.7 打包并压缩
6.5 zip压缩工具
- 直接压缩 格式 zip 1.txt.zip 1.txt //可以看到zip需要先命名文件
[[email protected] tmp]# ls -lh 1.txt 查看文件大小 -rw-r--r--. 1 root root 3.6M 11月 10 21:44 1.txt [[email protected] tmp]# zip 1.txt.zip 1.txt 执行zip命令压缩 adding: 1.txt (deflated 75%) [[email protected] tmp]# ls -lh 1.txt.zip -rw-r--r--. 1 root root 906K 11月 10 21:45 1.txt.zip 压缩容量变小
- 压缩目录 需要带 -r选项
[[email protected] tmp]# zip -r 123.zip 123/ adding: 123/ (stored 0%) adding: 123/1.txt (deflated 75%) [[email protected] tmp]# ls -lh 123 总用量 3.6M -rw-r--r--. 1 root root 3.6M 11月 10 21:55 1.txt [[email protected] tmp]# ls -lh 123.zip -rw-r--r--. 1 root root 906K 11月 10 21:55 123.zip
- 解压文件
[[email protected] tmp]# unzip 1.txt.zip Archive: 1.txt.zip replace 1.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: y 询问是否覆盖,由于不删除源文件 inflating: 1.txt #解压会有提示
- 解压目录
[[email protected] tmp]# unzip 123.zip -d /tmp/123/456/ 解压目录 加 -d 选项 可以创建目录 Archive: 123.zip #或 指定目录 creating: /tmp/123/456/123/ inflating: /tmp/123/456/123/1.txt
- 查看文件列表
[[email protected] tmp]# unzip -l 123.zip - l 选项 查看文件列表 Archive: 123.zip Length Date Time Name --------- ---------- ----- ---- 0 11-10-2017 21:55 123/ 3677600 11-10-2017 21:55 123/1.txt --------- ------- 3677600 2 files
备注:
zip命令没有可以用 yum install -y zip 命令安装zip包;
unzip命令没有可以用 yum install -y unzip 命令安装unzip包。
6.6 tar打包
常用的参数:
- -c 建立一个压缩文件的参数指令(create 的意思)
- -v 压缩的过程中显示文件
- -f 使用档名,请留意,在 f 之后要立即接档名喔!不要再加参数!
- -t 查看 tarfile 里面的文件
- -x 解开一个压缩文件的参数指令
示例:
- tar -cvf 123.tar 123 仅打包,不压缩
[[email protected] tmp]# tree 123 123 ├── 1.txt ├── 456 │ ├── 123 │ │ └── 1.txt │ └── 456.zip └── 789 ├── 789.txt └── 789.txt.zip 3 directories, 5 files [[email protected] tmp]# tar -cvf 123.tar 123 123/ 123/1.txt 123/456/ 123/456/123/ 123/456/123/1.txt 123/456/456.zip 123/789/ 123/789/789.txt.zip 123/789/789.txt
- tar -cvf linux.tar 1.txt 123 打包1.txt文件和123目录,并重名为linux.tar
[[email protected] tmp]# tar -cvf linux.tar 1.txt 123 1.txt 123/ 123/1.txt 123/456/ 123/456/123/ 123/456/123/1.txt 123/456/456.zip 123/789/ 123/789/789.txt.zip 123/789/789.txt [[email protected] tmp]# ls -lh linux.tar -rw-r--r--. 1 root root 16M 11月 10 22:33 linux.tar #容量比之前增加了
- tar -xvf linux.tar 解开linux.tar包
[[email protected] tmp]# tar -xvf linux.tar 1.txt 123/ 123/1.txt 123/456/ 123/456/123/ 123/456/123/1.txt 123/456/456.zip 123/789/ 123/789/789.txt.zip 123/789/789.txt
- tar -tf linux.tar 查看文件列表
[[email protected] tmp]# tar -tf linux.tar 1.txt 123/ 123/1.txt 123/456/ 123/456/123/ 123/456/123/1.txt 123/456/456.zip 123/789/ 123/789/789.txt.zip 123/789/789.txt
- tar -cvf aming.tar --exclude 1.txt --exclude 2 123 过滤指定的文件
[[email protected] tmp]# tar -cvf linux.tar --exclude 1.txt --exclude 2 123 123/ 123/456/ 123/456/123/ 123/456/456.zip 123/789/ 123/789/789.txt.zip 123/789/789.txt
6.7 打包并压缩
时间: 2024-07-29 23:46:56