zip命令能够压缩目录和文件,-r 压缩目录。数组
[root@yong-02 yyl]# zip 2.txt.zip 2.txt -bash: zip: 未找到命令 [root@yong-02 yyl]# yum install -y zip
[root@yong-02 gzip]# zip 2.txt.zip 2.txt adding: 2.txt (deflated 74%) [root@yong-02 gzip]# ls 1.txt 2.txt 2.txt.zip 3.txt 4.txt 5.txt yyl [root@yong-02 gzip]# du -sh 2.txt.zip 560K 2.txt.zip
[root@yong-02 gzip]# zip -r yyl.zip yyl adding: yyl/ (stored 0%) adding: yyl/1.txt (deflated 74%) adding: yyl/2.txt (deflated 74%) adding: yyl/3.txt (deflated 74%) adding: yyl/4.txt (deflated 74%) adding: yyl/5.txt (deflated 74%) [root@yong-02 gzip]# ls 1.txt 2.txt 2.txt.zip 3.txt 4.txt 5.txt yyl yyl.zip [root@yong-02 gzip]# du -sh yyl.zip 2.8M yyl.zip [root@yong-02 gzip]# du -sh yyl 11M yyl
[root@yong-02 gzip]# unzip yyl.zip -bash: unzip: 未找到命令 [root@yong-02 gzip]# yum install unzip
[root@yong-02 gzip]# unzip yyl.zip Archive: yyl.zip replace yyl/1.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: y inflating: yyl/1.txt replace yyl/2.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: A inflating: yyl/2.txt inflating: yyl/3.txt inflating: yyl/4.txt inflating: yyl/5.txt [root@yong-02 gzip]# ls 1.txt 2.txt 2.txt.zip 3.txt 4.txt 5.txt yyl yyl.zip
1.指定解压文件路径bash
[root@yong-02 gzip]# unzip yyl.zip -d test/ Archive: yyl.zip creating: test/yyl/ inflating: test/yyl/1.txt inflating: test/yyl/2.txt inflating: test/yyl/3.txt inflating: test/yyl/4.txt inflating: test/yyl/5.txt [root@yong-02 gzip]# ls test/yyl/ 1.txt 2.txt 3.txt 4.txt 5.txt
2.查看压缩文件内容列表工具
[root@yong-02 gzip]# unzip -l yyl.zip Archive: yyl.zip Length Date Time Name --------- ---------- ----- ---- 0 04-17-2018 11:30 yyl/ 2190726 04-17-2018 11:30 yyl/1.txt 2190726 04-17-2018 11:30 yyl/2.txt 2190726 04-17-2018 11:30 yyl/3.txt 2190726 04-17-2018 11:30 yyl/4.txt 2190726 04-17-2018 11:30 yyl/5.txt --------- ------- 10953630 6 files
打包目录yylspa
[root@yong-02 gzip]# tar -cvf yyl.tar yyl/ yyl/ yyl/1.txt yyl/2.txt yyl/3.txt yyl/4.txt yyl/5.txt
查看打包文件yyl.tar的内容code
[root@yong-02 gzip]# tar -tf yyl.tar yyl/ yyl/1.txt yyl/2.txt yyl/3.txt yyl/4.txt yyl/5.txt
解包文件yyl.tarip
[root@yong-02 gzip]# tar -xvf yyl.tar yyl/ yyl/1.txt yyl/2.txt yyl/3.txt yyl/4.txt yyl/5.txt
打包目录yyl ,可是不包含文件2.txt资源
[root@yong-02 gzip]# tar -cvf yyl.tar --exclude 2.txt yyl/ yyl/ yyl/1.txt yyl/3.txt yyl/4.txt yyl/5.txt
打包并压缩test
打包文件并使用gzip压缩可视化
[root@yong-02 gzip]# tar -czvf yyl.tar.gz yyl/ yyl/ yyl/1.txt yyl/2.txt yyl/3.txt yyl/4.txt yyl/5.txt
查看打包文件打包
[root@yong-02 gzip]# tar -tf yyl.tar.gz yyl/ yyl/1.txt yyl/2.txt yyl/3.txt yyl/4.txt yyl/5.txt
解压缩yyl.tar.gz
[root@yong-02 gzip]# tar -zxvf yyl.tar.gz yyl/ yyl/1.txt yyl/2.txt yyl/3.txt yyl/4.txt yyl/5.txt
打包文件并使用bzip2压缩
[root@yong-02 gzip]# tar -cjvf yyl.tar.bz2 yyl/ yyl/ yyl/1.txt yyl/2.txt yyl/3.txt yyl/4.txt yyl/5.txt
解压缩yyl.tar.bz2
[root@yong-02 gzip]# tar -xjvf yyl.tar.bz2 yyl/ yyl/1.txt yyl/2.txt yyl/3.txt yyl/4.txt yyl/5.txt
打包文件并使用xz压缩
[root@yong-02 gzip]# tar -cJvf yyl.tar.xz yyl/ yyl/ yyl/1.txt yyl/2.txt yyl/3.txt yyl/4.txt yyl/5.txt
解压缩yyl.tar.xz
[root@yong-02 gzip]# tar -xJvf yyl.tar.xz yyl/ yyl/1.txt yyl/2.txt yyl/3.txt yyl/4.txt yyl/5.txt
查看打包文件
[root@yong-02 gzip]# tar -tf yyl.tar.xz yyl/ yyl/1.txt yyl/2.txt yyl/3.txt yyl/4.txt yyl/5.txt
压缩包大小比较:
[root@yong-02 gzip]# du -sh yyl.tar.gz yyl.tar yyl.tar.bz2 yyl.tar.xz 2.8M yyl.tar.gz 11M yyl.tar 980K yyl.tar.bz2 60K yyl.tar.xz
注意:打包后文件越小,耗时越长,占用cpu资源越多。