zip压缩工具,tar打包,打包并压缩

zip压缩工具 (能够压缩目录)

概念:zip压缩包在Windows和Linux中都比较经常使用,
它能够压缩目录和文件,压缩目录时,须要指定目录下的文件。
zip后面先跟目标文件名(即压缩后的自定义的压缩包名),
而后跟要压缩的文件或者目录;
安装源码包:yum -y install zip
特色:压缩完了源文件不删除。
选项:
-r 压缩目录

zip压缩文件工具

[root@localhost d6z]# zip 2.txt.zip 2.txt #先跟目标文件名,再跟指定文件路径。
adding: 2.txt (deflated 75%)
[root@localhost d6z]# ls
1.txt 2.txt 2.txt.zip dior1spa

压缩目录和文件.net

[root@localhost d6z]# zip -r dior1.zip 2.txt dior1/ #压缩文件和目录
updating: dior1/ (stored 0%)
updating: dior1/1.txt (stored 0%)
adding: 2.txt (deflated 75%)
[root@localhost d6z]# ls 
1.txt 2.txt 2.txt.zip dior1 dior1.zipcode

解压zipblog

[root@localhost d6z]# yum -y install unzip #安装源码包
[root@localhost d6z]# unzip dior1.zip 
Archive: dior1.zip
replace dior1/1.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: #是否要覆盖,由于压缩的时候并无把源文件删除,是否须要覆盖 替换。 A 表示所有yesip

指定解压zip到哪里去get

[root@localhost d6z]# mkdir test #建立目录
[root@localhost d6z]# unzip 2.txt.zip -d test/ #解压缩2.txt.zip目录,-d指定到 test目录下。
Archive: 2.txt.zip
inflating: test/2.txt源码

zip不能够查看文件的内容,不过能够查看目录下都有哪些文件,示例以下:io

[root@localhost d6z]# unzip -l dior1.zip 
Archive: dior1.zip
Length Date Time Nameclass

0 04-14-2018 23:20 dior1/
7 04-14-2018 23:20 dior1/1.txt
215600 04-14-2018 23:18 2.txt

215607 3 files

tar打包工具

概念:tar自己就是一个打包工具,能够把目录打包成一个文件;
它把全部文件整合成一个大文件,方便复制或者移动;
命令格式:tar [zjxcvfpP] filename tar
经常使用选项:
-z 表示同时用gzip压缩
-j 表示同时用bzip2压缩
-J 表示同时用xz压缩
-x 表示解包或者解压缩
-t 表示查看tar包里面文件
-c 表示创建一tar包或者压缩文件包
-v 表示可视化
-f 后面跟文件名(-f filename,表示压缩后的文件名为filename;
或者压缩文件filename,若是是多个参数的话,须要把-f写到最前面。

用到的命令

tar -cvf 123.tar 123
tar -cvf

打包一个目录

[root@localhost d6z]# tar -cvf dior1.tar dior1
dior1/
dior1/1.txt
[root@localhost d6z]# ls 
1.txt 2.txt 2.txt.zip dior1 dior1.tar dior1.zip test

解包

[root@localhost d6z]# tar -cvf dior1.tar dior1
dior1/
dior1/1.txt
[root@localhost d6z]# ls 
1.txt 2.txt 2.txt.zip dior1 dior1.tar dior1.zip test

查看文件包里的内容

[root@localhost d6z]# tar -tf dior1.tar 
dior1/
dior1/1.txt

打包的时候过滤掉全部.txt的文件 --exclude

[root@localhost d6z]# tar -cvf dior1.tar --exclude ".txt" dior1
dior1/ #创建一个dior1.tar的压缩包, --exclude 过滤全部“
.txt”的文件 ,打包dior1

打包并压缩

加上选项“z” 表示压缩成gzip压缩包

[root@localhost d6z]# tar -zcvf dior2.tar.gz --exclude "*.txt" dior1
dior1/
[root@localhost d6z]# ls
1.txt 2.txt 2.txt.zip dior1 dior1.tar dior1.tar.gz dior1.zip dior2.tar.gz test

注:选项-zcvf表示 z打包的同事而且解压,建一个tar包 或压缩我呢见包, v 可视化, f 后面须要跟文件名,表示压缩后的文件名

2018.4.17 四周第五次课

加上j,表示打包的同时使用bzip2压缩
加上J,表示打包的同时使用xz压缩

相关文章
相关标签/搜索