zip压缩工具,tar打包工具

zip压缩工具

zip打包工具跟前面说到的gzip,bz2,xz 工具最大的不同是zip能够压缩目录。若是没有安装,须要使用yum install -y zip 来安装。安装完以后就能够直接使用了,跟以前提到的压缩工具第二个不同的地方是使用格式:zip XX.zip filename 这里的XX.zip是压缩后的压缩包名字。工具

[root@localhost tmp]# zip test.zip 1.txt
  adding: 1.txt (deflated 73%)
[root@localhost tmp]# du -h test.zip 
2.0M	test.zip
[root@localhost tmp]# ls
1.txt  1.txt.bz2  222  2.txt  3.txt  44.txt  form154853.pdf  test.zip

若是要使用zip压缩目录,则须要加-r的参数,应用以下code

[root@localhost tmp]# zip -r test3.zip 222
  adding: 222/ (stored 0%)
  adding: 222/1.txt.gz (deflated 0%)
  adding: 222/1.txt (stored 0%)
  adding: 222/11.txt (deflated 73%)
  adding: 222/333.txt (deflated 3%)
[root@localhost tmp]# du -sh test3.zip 
3.9M	test3.zip
[root@localhost tmp]# ls
1.txt  1.txt.bz2  222  2.txt  3.txt  44.txt  form154853.pdf  test1.zip  test3.zip  test.zip

使用zip还发现一个不同的地方就是默认它不会删除掉原文件。orm

zip的解压缩unzip

要解压缩zip压缩包须要使用unzip命令,默认没有安装,使用yum install -y unzip 命令安装。这个命令是能够指定目录的-d参数,可是不能更改解开的文件的名字ip

[root@localhost tmp]# unzip test.zip -d test     指定目录(就算是目录不存在)
Archive:  test.zip
  inflating: test/1.txt              
[root@localhost tmp]# ls
1.txt  1.txt.bz2  222  2.txt  3.txt  44.txt  form154853.pdf  test  test1.zip  test3.zip  test.zip                              也会产生-d后面跟的目录
[root@localhost tmp]# tree /tmp/test
/tmp/test
└── 1.txt

0 directories, 1 file

只用zip压缩的包不能使用zcat ,zmore 等命令查看包里文件的内容,可是能够使用unzip -l 来查看包里的文件列表form

[root@localhost tmp]# unzip -l test1.zip 
Archive:  test1.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  06-23-2018 01:18   222/
  2009225  06-23-2018 00:44   222/1.txt.gz
        0  06-23-2018 00:53   222/1.txt
  7487139  06-23-2018 00:54   222/11.txt
       32  06-23-2018 01:18   222/333.txt
---------                     -------
  9496396                     5 files

tar打包工具

tar打包工具能够把多个目录+多个文件打包成一个文件 用法 tar -cvf XXX.tar filename filename 这里面的filename能够是文件也能够是目录,若是使用tar -cf参数就什么都不提示了,没有了可视化的打包过程。pdf

[root@localhost tmp]# tar -cvf dabao.tar 1.txt 222 2.txt 1.txt.bz2 
1.txt
222/
222/1.txt.gz
222/1.txt
222/11.txt
222/333.txt
2.txt
1.txt.bz2
[root@localhost tmp]# tar -tf dabao.tar 
1.txt
222/
222/1.txt.gz
222/1.txt
222/11.txt
222/333.txt
2.txt
1.txt.bz2
[root@localhost tmp]# du -sh dabao.tar 
25M	dabao.tar

tar解包 tar -xvf

要解开tar打包的文件须要使用tar -xvf 命令test

[root@localhost mnt]# cp /tmp/dabao.tar /mnt 复制到该目录下是为了看起来比较清晰
[root@localhost mnt]# ls
dabao.tar
[root@localhost mnt]# tar -xvf dabao.tar  tar -xvf 解包
1.txt
222/
222/1.txt.gz
222/1.txt
222/11.txt
222/333.txt
2.txt
1.txt.bz2
[root@localhost mnt]# ls				解包后的结果
1.txt  1.txt.bz2  222  2.txt  dabao.tar

tar打包的时候能够过滤掉指定的文件可视化

[root@localhost mnt]# ls
1.txt  1.txt.bz2  222  2.txt  dabao.tar
[root@localhost mnt]# 
[root@localhost mnt]# tar -cvf dabao1.tar --exclude "*.txt" 222 1.txt.bz2 过滤掉全部“.txt”结尾的文件
222/
222/1.txt.gz
1.txt.bz2

打包并压缩

  • tar -zcvf 压缩包名.gz 文件名 (打包并使用gzip工具压缩)
  • tar -zxvf 压缩包名.gz (解压缩)
  • tar -jcvf 压缩包名.bz2 文件名 (打包并使用bz2工具压缩)
  • tar -jxvf 压缩包名.bz2 (解压缩)
  • tar -Jcvf 压缩包名.xz 文件名 (打包并使用xz工具压缩)
  • tar -Jxvf 压缩包名.xz (解压缩)
[root@localhost mnt]# tar -zcvf gz.gz 222 1.txt 打包并使用gzip压缩
222/
222/1.txt.gz
222/1.txt
222/11.txt
222/333.txt
1.txt
[root@localhost mnt]# ls
1.txt  1.txt.bz2  222  2.txt  dabao1.tar  dabao.tar  gz.gz
[root@localhost mnt]# tar -jcvf gz.bz2 222 1.txt 打包并使用bz2压缩
222/
222/1.txt.gz
222/1.txt
222/11.txt
222/333.txt
1.txt
[root@localhost mnt]# tar -Jcvf gz.xz 222 1.txt 打包并使用xz压缩
222/
222/1.txt.gz
222/1.txt
222/11.txt
222/333.txt
1.txt

解压缩

[root@localhost mnt]# tar -zxvf gz.gz 
222/
222/1.txt.gz
222/1.txt
222/11.txt
222/333.txt
1.txt
[root@localhost mnt]# tar -jxvf gz.bz2
222/
222/1.txt.gz
222/1.txt
222/11.txt
222/333.txt
1.txt
[root@localhost mnt]# tar -Jxvf gz.xz 
222/
222/1.txt.gz
222/1.txt
222/11.txt
222/333.txt
1.txt
相关文章
相关标签/搜索