Linux学习(七)压缩和解压类


前言

本文记录学习压缩和解压类,如有问题,请帮忙指出,谢谢。


提示:以下是本篇文章正文内容,下面案例可供参考

一、gzip/gunzip 压缩

基本语法

gzip 文件 (功能描述:压缩文件,只能将文件压缩为*.gz文件)
gunzip 文件.gz (功能描述:解压缩文件命令)

经验技巧

(1)只能压缩文件不能压缩目录
(2)不保留原来的文件

案例实操

gzip压缩

[root@hadoop1 ~]# ls
test.java
[root@hadoop1 ~]# gzip test.txt
[root@hadoop1 ~]# ls
test.txt.gz

gunzip解压缩文件

[root@hadoop1 ~]# gunzip test.txt.gz 
[root@hadoop1 ~]# ls
test.txt

二、zip/unzip 压缩

基本语法

zip [选项] XXX.zip 将要压缩的内容 (功能描述:压缩文件和目录的命令)
unzip [选项] XXX.zip (功能描述:解压缩文件)

选项说明

zip
选项说明
unzip
选项说明

经验技巧

zip 压缩命令在window/linux都通用,可以压缩目录且保留源文件。

案例实操

压缩 1.txt 和2.txt,压缩后的名称为t.zip

[root@hadoop1 opt]# touch t2.txt
[root@hadoop1 opt]# zip t.zip test.txt t2.txt 
  adding: test.txt (stored 0%)
  adding: t2.txt (stored 0%)
[root@hadoop1 opt]# ls
test.txt	t2.txt	t.zip 

解压 t.zip

[root@hadoop101 ~]# unzip t.zip 
Archive:  t.zip
 extracting: test.txt               
 extracting: t2.txt       
[root@hadoop101 ~]# ls
test.txt	t2.txt	t.zip

解压t.zip到指定目录-d

[root@hadoop101 ~]# unzip t.zip -d /opt
[root@hadoop101 ~]# ls /opt/

三、tar 打包

基本语法

tar [选项] XXX.tar.gz 将要打包进去的内容 (功能描述:打包目录,压缩后的文件格式.tar.gz)

选项说明

选项说明

案例实操

压缩多个文件

[root@hadoop101 opt]# tar -zcvf t.tar.gz test.txt t2.txt 
test.txt
t2.txt
[root@hadoop101 opt]# ls
t.tar.gz test.txt t2.txt 

压缩目录

[root@hadoop101 ~]# tar -zcvf tt.tar.gz tt/
tt/
tt/mingjie/
tt/dssz/
tt/dssz/test.txt

解压到当前目录

[root@hadoop101 ~]# tar -zxvf t.tar.gz

解压到指定目录

[root@hadoop101 ~]# tar -zxvf tt.tar.gz -C /opt
[root@hadoop101 ~]# ll /opt/

总结

在我工作中tar用的比较多,注意选项组合,分清压缩和解压。tar指定解压目录前要记得加-C。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

请看我头像

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值