• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
YJ
博客园    首页    新随笔    联系   管理    订阅  订阅

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

000 016

gzip/gunzip 压缩

1.基本语法

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

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

2.经验技巧

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

(2)不保留原来的文件

3.案例实操

(1)gzip压缩

[root@hadoop101 ~]# ls

test.java

[root@hadoop101 ~]# gzip houge.txt

[root@hadoop101 ~]# ls

houge.txt.gz

(2)gunzip解压缩文件

[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/

posted @ 2019-09-23 01:06  51人去楼空  阅读(132)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3