zip压缩工具
- zip 1.txt.zip 1.txt
- zip -r 123.zip 123/
- unzip 1.txt.zip
- unzip 123.zip -d ./123/
- unzip -l 123.zip
//安装zip
[root@24centos7-01 test]# yum install -y zip
[root@24centos7-01 test]# yum install -y unzip
//压缩
[root@24centos7-01 test]# zip 1.txt.zip 1.txt
adding: 1.txt (deflated 69%)
[root@24centos7-01 test]# ls
1.txt 1.txt.zip 2.txt test
[root@24centos7-01 test]# du -sh 1.txt.zip
336K 1.txt.zip
//压缩文件及目录
[root@24centos7-01 test]# zip -r test.zip 2.txt test
adding: 2.txt (deflated 69%)
adding: test/ (stored 0%)
adding: test/1.txt (deflated 69%)
adding: test/2.txt (deflated 69%)
[root@24centos7-01 test]# ls
1.txt 1.txt.zip 2.txt test test.zip
[root@24centos7-01 test]# du -sh test.zip
1004K test.zip
//有同名文件或目录时解压
[root@24centos7-01 test]# unzip test.zip
Archive: test.zip
replace 2.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: A //提示你是否覆盖;是,否,所有,不,重命名
inflating: 2.txt
inflating: test/1.txt
inflating: test/2.txt
//解压到指定目录
[root@24centos7-01 test]# unzip test.zip -d ./test/test
Archive: test.zip
inflating: ./test/test/2.txt
creating: ./test/test/test/
inflating: ./test/test/test/1.txt
inflating: ./test/test/test/2.txt
//查看压缩包里的文件列表
[root@24centos7-01 test]# unzip -l test.zip
Archive: test.zip
Length Date Time Name
--------- ---------- ----- ----
1110943 11-09-2017 21:02 2.txt
0 11-09-2017 22:16 test/
1110943 11-09-2017 22:16 test/1.txt
1110943 11-09-2017 22:16 test/2.txt
--------- -------
3332829 4 files
tar打包
- tar -cvf 123.tar 123
- tar -cvf test.tar 1.txt 123
- tar -xvf test.tar
- tar -tv test.tar
- tar -cvf test.tar --exclude 1.txt --exclude 2 123
//将test目录打包
[root@24centos7-01 test]# ls
1.txt 1.txt.zip 2.txt test test.zip
[root@24centos7-01 test]# tar -cvf test.tar test/
test/
test/1.txt
test/2.txt
test/test/
test/test/2.txt
test/test/test/
test/test/test/1.txt
test/test/test/2.txt
[root@24centos7-01 test]# ls
1.txt 1.txt.zip 2.txt test test.tar test.zip
//将test目录及其余文件一块儿打包
[root@24centos7-01 test]# tar -cvf test.tar test 1.txt 1.txt.zip
test/
test/1.txt
test/2.txt
test/test/
test/test/2.txt
test/test/test/
test/test/test/1.txt
test/test/test/2.txt
1.txt
1.txt.zip
[root@24centos7-01 test]# ls
1.txt 1.txt.zip 2.txt test test.tar test.zip
//使用-t参数显示tar包中的文件和目录列表
[root@24centos7-01 test]# tar -tf test.tar
test/
test/1.txt
test/2.txt
test/test/
test/test/2.txt
test/test/test/
test/test/test/1.txt
test/test/test/2.txt
1.txt
1.txt.zip
//使用--exclude在打包的过程当中排除部分文件和目录
[root@24centos7-01 test]# tar -cvf test.tar --exclude 1.txt test
test/
test/2.txt
test/test/
test/test/2.txt
test/test/test/
test/test/test/2.txt
//无--exclude参数
[root@24centos7-01 test]# tar -cvf test.tar test
test/
test/1.txt
test/2.txt
test/test/
test/test/2.txt
test/test/test/
test/test/test/1.txt
test/test/test/2.txt
//多个--exclude状况,不支持一个--exclude使用多参数
[root@24centos7-01 test]# tar -cvf test.tar --exclude 1.txt --exclude "*.txt" test
test/
test/test/
test/test/test/
打包并压缩
tar -cvf建立tar包 -xvf解包 -tf查看列表 --exclude排除文件或目录 -z表明gzip -j表明bz2 -J借用xz -C指定解压的目标目录 -v显示档案列表
- tar -zcvf test.tar.gz test
- tar -zxvf test.tar.gz
- tar -jcvf test.bz2 test
- tar -jxvf test.bz2
- tar -Jcvf test.xz test
- tar -Jxvf test.xz
- tar -tf test.bz2
- tar -tf test.gz
- tar -tf test.xz
//打包时使用gzip压缩
[root@24centos7-01 test]# ls
1.txt 1.txt.zip 2.txt test test.zip
[root@24centos7-01 test]# tar -zcvf test.tar.gz test 1.txt 1.txt.zip test.zip
test/
test/1.txt
test/2.txt
test/test/
test/test/2.txt
test/test/test/
test/test/test/1.txt
test/test/test/2.txt
1.txt
1.txt.zip
test.zip
[root@24centos7-01 test]# ls
1.txt 1.txt.zip 2.txt test test.tar.gz test.zip
[root@24centos7-01 test]# du -sh test 1.txt 1.txt.zip test.zip
5.4M test
1.1M 1.txt
336K 1.txt.zip
1004K test.zip
[root@24centos7-01 test]# du -sh test.tar.gz
3.3M test.tar.gz
//打包时使用bz2压缩
[root@24centos7-01 test]# tar -jcvf test.tar.bz2 test 1.txt 1.txt.zip test.zip
test/
test/1.txt
test/2.txt
test/test/
test/test/2.txt
test/test/test/
test/test/test/1.txt
test/test/test/2.txt
1.txt
1.txt.zip
test.zip
[root@24centos7-01 test]# ls
1.txt 1.txt.zip 2.txt test test.tar.bz2 test.zip
[root@24centos7-01 test]# du -sh test.tar.bz2
2.8M test.tar.bz2
//打包时使用xz压缩
[root@24centos7-01 test]# tar -Jcvf test.tar.xz test 1.txt 1.txt.zip test.zip
test/
test/1.txt
test/2.txt
test/test/
test/test/2.txt
test/test/test/
test/test/test/1.txt
test/test/test/2.txt
1.txt
1.txt.zip
test.zip
[root@24centos7-01 test]# du -sh test.tar.xz
612K test.tar.xz
//查看文件列表,不区分压缩格式
[root@24centos7-01 test]# tar -tf test.tar.bz2
test/
test/1.txt
test/2.txt
test/test/
test/test/2.txt
test/test/test/
test/test/test/1.txt
test/test/test/2.txt
1.txt
1.txt.zip
test.zip
[root@24centos7-01 test]# tar -tf test.tar.xz
test/
test/1.txt
test/2.txt
test/test/
test/test/2.txt
test/test/test/
test/test/test/1.txt
test/test/test/2.txt
1.txt
1.txt.zip
test.zip
//未压缩tar包也支持-tf
[root@24centos7-01 test]# tar -tf test.tar
test/
test/1.txt
test/2.txt
test/test/
test/test/2.txt
test/test/test/
test/test/test/1.txt
test/test/test/2.txt
//指定解压的目标目录
[root@24centos7-01 test]# tar -zxvf test.tar.gz -C ../
test/
test/1.txt
test/2.txt
test/test/
test/test/2.txt
test/test/test/
test/test/test/1.txt
test/test/test/2.txt