6.5 zip压缩工具
zip命令:压缩后原文件不被删除,可以支持压缩目录。
[root@lgs-01 ~]# zip abc.zip abc adding: abc (deflated 65%)[root@lgs-01 ~]# ls -l abc-rwxr-xr-x. 1 root root 3073568 4月 16 18:00 abc[root@lgs-01 ~]# ls -l abc.zip -rw-r--r--. 1 root root 1090963 4月 17 23:18 abc.zip[root@lgs-01 ~]# du -sh abc.zip 1.1M abc.zip
压缩目录:-r选项
[root@lgs-01 ~]# zip -r 123.zip ./c/ abc adding: c/ (stored 0%) adding: c/x/ (stored 0%) adding: c/y/ (stored 0%) adding: c/6.txt.bak (stored 0%) adding: c/4.txt.bak (stored 0%) adding: c/3.txt.bak (stored 0%) adding: c/10.txt.bak (stored 0%) adding: c/11.txt.bak (deflated 98%) adding: c/666.gz (stored 0%) adding: c/abc1.bz2 (deflated 0%) adding: c/abc1.xz (deflated 0%) adding: abc (deflated 65%)[root@lgs-01 ~]# du -sh 123.zip 2.9M 123.zip
解压缩: unzip
[root@lgs-01 ~]# unzip 123.zipArchive: 123.zipreplace c/6.txt.bak? [y]es, [n]o, [A]ll, [N]one, [r]ename: A extracting: c/6.txt.bak extracting: c/4.txt.bak extracting: c/3.txt.bak extracting: c/10.txt.bak inflating: c/11.txt.bak extracting: c/666.gz inflating: c/abc1.bz2 inflating: c/abc1.xz inflating: abc
指定解压到哪个目录:-d
[root@lgs-01 ~]# unzip 123.zip -d ./b/Archive: 123.zip creating: ./b/c/ creating: ./b/c/x/ creating: ./b/c/y/ extracting: ./b/c/6.txt.bak extracting: ./b/c/4.txt.bak extracting: ./b/c/3.txt.bak extracting: ./b/c/10.txt.bak inflating: ./b/c/11.txt.bak extracting: ./b/c/666.gz inflating: ./b/c/abc1.bz2 inflating: ./b/c/abc1.xz inflating: ./b/abc [root@lgs-01 ~]# ls -l ./b/总用量 3004-rwxr-xr-x. 1 root root 3073568 4月 16 18:00 abcdrwxr-xr-x. 4 root root 156 4月 17 23:28 c
查看zip压缩文件的文件列表,不能查看文件内容:unzip -l
[root@lgs-01 ~]# unzip -l 123.zip Archive: 123.zip Length Date Time Name--------- ---------- ----- ---- 0 04-17-2018 23:28 c/ 0 03-30-2018 12:33 c/x/ 0 03-30-2018 12:39 c/y/ 0 03-28-2018 16:36 c/6.txt.bak 0 03-28-2018 16:40 c/4.txt.bak 0 03-30-2018 12:33 c/3.txt.bak 0 03-30-2018 12:39 c/10.txt.bak 8294 04-01-2018 21:56 c/11.txt.bak 1656 04-16-2018 18:15 c/666.gz 1078029 04-16-2018 18:27 c/abc1.bz2 831676 04-16-2018 18:35 c/abc1.xz 3073568 04-16-2018 18:00 abc--------- ------- 4993223 12 files
6.6 tar打包
tar:打包命令,对文件大小变化不大。
[root@lgs-01 ~]# tar -cvf abc.tar ./c./c/./c/x/./c/y/./c/6.txt.bak./c/4.txt.bak./c/3.txt.bak./c/10.txt.bak./c/11.txt.bak./c/666.gz./c/abc1.bz2./c/abc1.xz[root@lgs-01 ~]# du -sh ./c1.9M ./c[root@lgs-01 ~]# du -sh abc.tar 1.9M abc.tar
目录和文件一起打包:
[root@lgs-01 ~]# tar -cvf 333.tar b/ abc zb.txtb/b/c/b/c/x/b/c/y/b/c/6.txt.bakb/c/4.txt.bakb/c/3.txt.bakb/c/10.txt.bakb/c/11.txt.bakb/c/666.gzb/c/abc1.bz2b/c/abc1.xzb/abcabczb.txt[root@lgs-01 ~]# du -sh 333.tar 7.8M 333.tar
解包:-xvf。会覆盖原文件和目录,不会提示
[root@lgs-01 ~]# tar -xvf 333.tar b/b/c/b/c/x/b/c/y/b/c/6.txt.bakb/c/4.txt.bakb/c/3.txt.bakb/c/10.txt.bakb/c/11.txt.bakb/c/666.gzb/c/abc1.bz2b/c/abc1.xzb/abcabczb.txt
查看包文件列表:-tf
[root@lgs-01 ~]# tar -tf 333.tar b/b/c/b/c/x/b/c/y/b/c/6.txt.bakb/c/4.txt.bakb/c/3.txt.bakb/c/10.txt.bakb/c/11.txt.bakb/c/666.gzb/c/abc1.bz2b/c/abc1.xzb/abcabczb.txt
排除文件打包:--exclude
[root@lgs-01 ~]# tar -cvf 888.tar b/ abc c/ --exclude "*.bak"b/b/c/b/c/x/b/c/y/b/c/666.gzb/c/abc1.bz2b/c/abc1.xzb/abcabcc/c/x/c/y/c/666.gzc/abc1.bz2c/abc1.xz
6.7 打包并压缩
tar -czvf:打包并压缩成gz。 -xzvf 解压
[root@lgs-01 ~]# tar -czvf 9.tar.gz abc zb.txt b/abczb.txtb/b/c/b/c/x/b/c/y/b/c/6.txt.bakb/c/4.txt.bakb/c/3.txt.bakb/c/10.txt.bakb/c/11.txt.bakb/c/666.gzb/c/abc1.bz2b/c/abc1.xzb/abc[root@lgs-01 ~]# du -sh 9.tar.gz 4.0M 9.tar.gz
tar -cjvf:打包并压缩成bz2。 -jzvf 解压
[root@lgs-01 ~]# tar cjvf 7.tar.bz2 c/ xxx.conf.xz 123.zip c/c/x/c/y/c/6.txt.bakc/4.txt.bakc/3.txt.bakc/10.txt.bakc/11.txt.bakc/666.gzc/abc1.bz2c/abc1.xzxxx.conf.xz123.zip[root@lgs-01 ~]# du -sh 7.tar.bz2 4.8M 7.tar.bz2
tar -cJvf:打包并压缩成xz。 -Jzvf 解压
[root@lgs-01 ~]# tar -cJvf 5.tar.xz c/ abc b/ passwdtest c/c/x/c/y/c/6.txt.bakc/4.txt.bakc/3.txt.bakc/10.txt.bakc/11.txt.bakc/666.gzc/abc1.bz2c/abc1.xzabcb/b/c/b/c/x/b/c/y/b/c/6.txt.bakb/c/4.txt.bakb/c/3.txt.bakb/c/10.txt.bakb/c/11.txt.bakb/c/666.gzb/c/abc1.bz2b/c/abc1.xzb/abcpasswdtest[root@lgs-01 ~]# du -sh 5.tar.xz 2.6M 5.tar.xz
查看文件列表:tar -tf
[root@lgs-01 ~]# tar -tf 7.tar.bz2 c/c/x/c/y/c/6.txt.bakc/4.txt.bakc/3.txt.bakc/10.txt.bakc/11.txt.bakc/666.gzc/abc1.bz2c/abc1.xzxxx.conf.xz123.zip