Linux 下压缩解压缩有那么难吗?.tar.gz和.gz文件解压详解

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:参数详细显示处理的文件

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值