zip .tar.gz和.gz文件是两种不同的文件的详细解说
.gz文件,这种文件是tar文件的压缩文件,可以使用tar命令进行解压。
例如:
压缩:
[root@server001 myfile]# touch k8s{1..5}.sh
[root@server001 myfile]# ll
total 0
-rw-r--r-- 1 root root 0 Oct 20 22:49 k8s1.sh
-rw-r--r-- 1 root root 0 Oct 20 22:49 k8s2.sh
-rw-r--r-- 1 root root 0 Oct 20 22:49 k8s3.sh
-rw-r--r-- 1 root root 0 Oct 20 22:49 k8s4.sh
-rw-r--r-- 1 root root 0 Oct 20 22:49 k8s5.sh
[root@server001 myfile]# ls
k8s1.sh k8s2.sh k8s3.sh k8s4.sh k8s5.sh
[root@server001 myfile]# zip -r myfile.zip *.sh
adding: k8s1.sh (stored 0%)
adding: k8s2.sh (stored 0%)
adding: k8s3.sh (stored 0%)
adding: k8s4.sh (stored 0%)
adding: k8s5.sh (stored 0%)
[root@server001 myfile]#
解压一个zip文件(命令):
[root@server001 myfile]# unzip myfile.zip
[root@server001 myfile]# ll
total 4
-rw-r--r-- 1 root root 0 Oct 20 22:49 k8s1.sh
-rw-r--r-- 1 root root 0 Oct 20 22:49 k8s2.sh
-rw-r--r-- 1 root root 0 Oct 20 22:49 k8s3.sh
-rw-r--r-- 1 root root 0 Oct 20 22:49 k8s4.sh
-rw-r--r-- 1 root root 0 Oct 20 22:49 k8s5.sh
-rw-r--r-- 1 root root 732 Oct 20 22:50 myfile.zip
tar/tar.gz格式
tar是在Linux中使用得非常广泛的文档打包格式。它的好处就是它只消耗非常少的CPU以及时间去打包文件,它仅仅只是一个打包工具,并不负责压缩。
[root@server001 myfile]# tar -cvf myfile.tar *.sh k8s1.sh k8s2.sh k8s3.sh k8s4.sh k8s5.sh [root@server001 myfile]# ls k8s1.sh k8s2.sh k8s3.sh k8s4.sh k8s5.sh myfile.tar myfile.zip [root@server001 myfile]# gzip myfile.tar [root@server001 myfile]# ll total 8 -rw-r--r-- 1 root root 0 Oct 20 22:49 k8s1.sh -rw-r--r-- 1 root root 0 Oct 20 22:49 k8s2.sh -rw-r--r-- 1 root root 0 Oct 20 22:49 k8s3.sh -rw-r--r-- 1 root root 0 Oct 20 22:49 k8s4.sh -rw-r--r-- 1 root root 0 Oct 20 22:49 k8s5.sh -rw-r--r-- 1 root root 157 Oct 20 22:57 myfile.tar.gz -rw-r--r-- 1 root root 732 Oct 20 22:50 myfile.zip [root@server001 myfile]#
解包到指定的路径
[root@server001 ~]# cd myfile/
[root@server001 myfile]# gzip -d myfile.tar.gz
[root@server001 myfile]# tar -xvf myfile.tar
k8s1.sh
k8s2.sh
k8s3.sh
k8s4.sh
k8s5.sh
[root@server001 myfile]# ls
k8s1.sh k8s2.sh k8s3.sh k8s4.sh k8s5.sh myfile.tar myfile.zip
[root@server001 myfile]#
[root@server001 myfile]# cd
[root@server001 ~]# cd myfile/
[root@server001 myfile]# ls
k8s1.sh k8s2.sh k8s3.sh k8s4.sh k8s5.sh myfile.tar myfile.zip sre
[root@server001 myfile]# tar -xvf myfile.tar -C ./sre/
k8s1.sh
k8s2.sh
k8s3.sh
k8s4.sh
k8s5.sh
[root@server001 myfile]# cd sre/
[root@server001 sre]# ls
k8s1.sh k8s2.sh k8s3.sh k8s4.sh k8s5.sh
[root@server001 sre]#
最后再解释一下一些参数的定义:
-c:参数是建立新的存档
-f:参数指定存档或设备
-x:释放文件内存
-t:仅仅查看包中内容,而不释放
-v:参数详细显示处理的文件