20190923-08Linux压缩和解压类 000 016

本文详细介绍了Linux中常用的压缩工具gzip, gunzip, zip, unzip以及tar的使用方法,包括压缩、解压缩的基本语法、技巧和实战案例,适用于文件和目录的操作。" 116759172,10296513,Redhat Linux 硬盘挂载教程,"['Linux', 'Redhat', '硬盘管理', '系统管理']

gzip/gunzip 压缩

1.基本语法

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

gunzip 文件.gz (功能描述:解压缩文件命令)

2.经验技巧

1只能压缩文件不能压缩目录

2不保留原来的文件

3.案例实操

1gzip压缩

[root@hadoop101 ~]# ls

test.java

[root@hadoop101 ~]# gzip houge.txt

[root@hadoop101 ~]# ls

houge.txt.gz

2gunzip解压缩文件

[root@hadoop101 ~]# gunzip houge.txt.gz

[root@hadoop101 ~]# ls

houge.txt

 

zip/unzip 压缩

1.基本语法

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

unzip [选项] XXX.zip (功能描述:解压缩文件)

2.选项说明

1-29

zip选项

功能

-r

压缩目录

1-30

unzip选项

功能

-d<目录>

指定解压后文件的存放目录

3.经验技巧

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

4.案例实操

1)压缩 1.txt 2.txt,压缩后的名称为mypackage.zip

[root@hadoop101 opt]# touch bailongma.txt

[root@hadoop101 ~]# zip houma.zip houge.txt bailongma.txt

  adding: houge.txt (stored 0%)

  adding: bailongma.txt (stored 0%)

[root@hadoop101 opt]# ls

houge.txt bailongma.txt houma.zip

2)解压 mypackage.zip

[root@hadoop101 ~]# unzip houma.zip

Archive:  houma.zip

 extracting: houge.txt               

 extracting: bailongma.txt       

[root@hadoop101 ~]# ls

houge.txt bailongma.txt houma.zip

3)解压mypackage.zip到指定目录-d

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

[root@hadoop101 ~]# ls /opt/

 

tar 打包

1.基本语法

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

2.选项说明

1-31

选项

功能

-z

打包同时压缩

-c

产生.tar打包文件

-v

显示详细信息

-f

指定压缩后的文件名

-x

解包.tar文件

3.案例实操

1)压缩多个文件

[root@hadoop101 opt]# tar -zcvf houma.tar.gz houge.txt bailongma.txt

houge.txt

bailongma.txt

[root@hadoop101 opt]# ls

houma.tar.gz houge.txt bailongma.txt

2压缩目录

[root@hadoop101 ~]# tar -zcvf xiyou.tar.gz xiyou/

xiyou/

xiyou/mingjie/

xiyou/dssz/

xiyou/dssz/houge.txt

3)解压到当前目录

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

4解压到指定目录

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

[root@hadoop101 ~]# ll /opt/

转载于:https://www.cnblogs.com/YUJIE666/p/11570195.html

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值