目录

  • gzip
  • gunzip
  • tar(打包压缩)
  • tar(解包解压)
  • zip
  • unzip
  • bzip2
  • bunzip2

gzip

解释

命令名称:gzip
命令英文原意:GUN zip
命令所在路径:/bin/gzip
执行权限:所有用户
功能描述:压缩文件

语法

# 压缩后文件格式.gz
gzip [文件]

示例

# 压缩文件
gzip /tmp/services [root@izm5e2q95pbpe1hh0kkwoiz ~]# ls /tmp
Aegis-<Guid(5A2C30A2-A87D-490A-9281-6765EDAD7CBA)> php-cgi.sock
hsperfdata_root services
issue.hard systemd-private-9255c5ee9ec84f5987c1d9ba485e177e-ntpd.service-eKcnmD
issue.soft test
Japan test.txt
mysql.sock
[root@izm5e2q95pbpe1hh0kkwoiz ~]# gzip /tmp/services
[root@izm5e2q95pbpe1hh0kkwoiz ~]# ls -lh /etc/services
-rw-r--r--. 1 root root 655K Jun 7 2013 /etc/services
[root@izm5e2q95pbpe1hh0kkwoiz ~]# ls -lh /tmp/services.gz
-rw-r--r-- 1 root root 133K Nov 29 17:45 /tmp/services.gz # 压缩前655k,压缩后133k

gzip只能压缩文件,而且压缩后,原文件不在了

gunzip

解释

命令名称:gunzip
命令英文原意:GUN unzip
命令所在路径:/bin/gunzip
执行权限:所有用户
功能描述:解压缩.gz文件

语法

# 解压缩.gz文件
gunzip [文件]

示例

# 解压缩services.gz文件
gunzip services.gz

tar

解释

命令名称:tar
命令所在路径:/bin/tar
执行权限:所有用户
功能描述:打包目录

语法

tar 选项[-zcf] [压缩后文件名] [被打包的目录]
-c 打包
-v 显示详细信息
-f 指定文件名
-z 打包同时压缩

示例

# 打包并压缩文件
tar -czf Japan.tar.gz /tmp/Japan
tar -zcf Japan.tar.gz /tmp/Japan # -f必须处于最后面,否则报错
tar -zfc Japan.tar.gz /tmp/Japan [root@izm5e2q95pbpe1hh0kkwoiz ~]# tar -zfc Japan.tar.gz /tmp/Japan
tar: You must specify one of the `-Acdtrux' or `--test-label' options
Try `tar --help' or `tar --usage' for more information.
[root@izm5e2q95pbpe1hh0kkwoiz ~]# tar -zcf Japan.tar.gz /tmp/Japan
tar: Removing leading `/' from member names
[root@izm5e2q95pbpe1hh0kkwoiz ~]# ls
boduo Japan.tar.gz lnmp-install.log test.txt
[root@izm5e2q95pbpe1hh0kkwoiz ~]# rm Japan.tar.gz
rm: remove regular file ‘Japan.tar.gz’? y
[root@izm5e2q95pbpe1hh0kkwoiz ~]# tar -czf Japan.tar.gz /tmp/Japan
tar: Removing leading `/' from member names
[root@izm5e2q95pbpe1hh0kkwoiz ~]# ls
boduo Japan.tar.gz lnmp-install.log test.txt

tar

解释

命令名称:tar
命令所在路径:/bin/tar
执行权限:所有用户
功能描述:解包解压缩目录

语法

tar 选项[-zcf] [压缩后文件名] [被打包的目录]
-x 解包
-v 显示详细信息
-f 指定解压文件
-z 解压缩

示例

# 解压缩目录(解压到当前目录)
tar -zxvf Japan.tar.gz [root@izm5e2q95pbpe1hh0kkwoiz ~]# ls
boduo Japan.tar.gz lnmp-install.log test.txt
[root@izm5e2q95pbpe1hh0kkwoiz ~]# tar -zxvf Japan.tar.gz
tmp/Japan/
tmp/Japan/cangjing/
tmp/Japan/boduo/
tmp/Japan/longze/
[root@izm5e2q95pbpe1hh0kkwoiz ~]# ls

zip

解释

命令名称:zip
命令所在路径:/usr/bin/zip
执行权限:所有用户
功能描述:压缩文件或目录

语法

# 压缩后的文件格式为zip
zip 选项[-r] [压缩后文件名] [被压缩的文件或目录]
-r 压缩目录

zip命令找不到

[root@izm5e2q95pbpe1hh0kkwoiz tmp]# zip aaa.zip test
-bash: zip: command not found 解决方法:
yum -y install zip

示例

# 压缩/tmp目录下的test文件为aaa.zip
zip aaa.zip test [root@izm5e2q95pbpe1hh0kkwoiz tmp]# zip aaa.zip test
adding: test/ (stored 0%)
[root@izm5e2q95pbpe1hh0kkwoiz tmp]# ls
aaa.zip
Aegis-<Guid(5A2C30A2-A87D-490A-9281-6765EDAD7CBA)>
hsperfdata_root
issue.hard
issue.soft
Japan
mysql.sock
php-cgi.sock
services
systemd-private-9255c5ee9ec84f5987c1d9ba485e177e-ntpd.service-eKcnmD
test
test.txt # 压缩/tmp下的Japan目录
zip -r Japan.zip Japan [root@izm5e2q95pbpe1hh0kkwoiz tmp]# zip -r Japan.zip Japan
adding: Japan/ (stored 0%)
adding: Japan/cangjing/ (stored 0%)
adding: Japan/boduo/ (stored 0%)
adding: Japan/longze/ (stored 0%)
[root@izm5e2q95pbpe1hh0kkwoiz tmp]# ls
aaa.zip
Aegis-<Guid(5A2C30A2-A87D-490A-9281-6765EDAD7CBA)>
hsperfdata_root
issue.hard
issue.soft
Japan
Japan.zip
mysql.sock
php-cgi.sock
services
systemd-private-9255c5ee9ec84f5987c1d9ba485e177e-ntpd.service-eKcnmD
test
test.txt

相对比gzip来说zip可以保留原文件,可以压缩目录

unzip

解释

命令名称:unzip
命令所在路径:/usr/bin/unzip
执行权限:所有用户
功能描述:解压.zip的压缩文件

语法

unzip [压缩文件]

示例

# 解压aaa.zip文件
unzip aaa.zip [root@izm5e2q95pbpe1hh0kkwoiz tmp]# unzip aaa.zip
Archive: aaa.zip
creating: test/

bzip2

解释

命令名称:bzip2
命令所在路径:/usr/bin/bzip2
执行权限:所有用户
功能描述:压缩文件

语法

# 压缩后的文件格式为.bz2
bzip2 选项[-k] [文件]
-k 差生压缩文件后保留原文件

示例

# 压缩文件
bzip2 -k boduo [root@izm5e2q95pbpe1hh0kkwoiz tmp]# touch boduo
[root@izm5e2q95pbpe1hh0kkwoiz tmp]# bzip2 -k boduo
[root@izm5e2q95pbpe1hh0kkwoiz tmp]# ls
aaa.zip
Aegis-<Guid(5A2C30A2-A87D-490A-9281-6765EDAD7CBA)>
boduo
boduo.bz2
hsperfdata_root
issue.hard
issue.soft
Japan
Japan.zip
mysql.sock
php-cgi.sock
services
systemd-private-9255c5ee9ec84f5987c1d9ba485e177e-ntpd.service-eKcnmD
test
test.txt # 将目录压缩为.bz2
tar -cjf Japan.tar.bz2 Japan [root@izm5e2q95pbpe1hh0kkwoiz tmp]# tar -cjf Japan.tar.bz2 Japan
[root@izm5e2q95pbpe1hh0kkwoiz tmp]# ls
aaa.zip
Aegis-<Guid(5A2C30A2-A87D-490A-9281-6765EDAD7CBA)>
boduo
boduo.bz2
hsperfdata_root
issue.hard
issue.soft
Japan
Japan.tar.bz2
Japan.zip
mysql.sock
php-cgi.sock
services
systemd-private-9255c5ee9ec84f5987c1d9ba485e177e-ntpd.service-eKcnmD
test
test.txt

只能压缩文件

bunzip2

解释

命令名称:bunzip2
命令所在路径:/usr/bin/bunzip2
执行权限:所有用户
功能描述:解压缩

语法

bunzip2 选项[-k] [压缩文件名]
-k 解压后保留原压缩文件

示例

# 解压文件
bunzip2 [root@izm5e2q95pbpe1hh0kkwoiz tmp]# bunzip2 boduo.bz2
bunzip2: Output file boduo already exists.
[root@izm5e2q95pbpe1hh0kkwoiz tmp]# rm boduo
rm: remove regular empty file ‘boduo’? y
[root@izm5e2q95pbpe1hh0kkwoiz tmp]# bunzip2 boduo.bz2
[root@izm5e2q95pbpe1hh0kkwoiz tmp]# ls
aaa.zip
Aegis-<Guid(5A2C30A2-A87D-490A-9281-6765EDAD7CBA)>
boduo
hsperfdata_root
issue.hard
issue.soft
Japan
Japan.tar.bz2
Japan.zip
mysql.sock
php-cgi.sock
services
systemd-private-9255c5ee9ec84f5987c1d9ba485e177e-ntpd.service-eKcnmD
test
test.txt # 解压目录
tar -xjf Japan.tar.bz2 # 不会报文件夹已存在的冲突,应该会合并

linux中压缩解压缩命令的更多相关文章

  1. linux下压缩解压缩命令

    zip/gzip 命令 linux zip命令参数列表:   -a 将文件转成ASCII模式 -F 尝试修复损坏的压缩文件 -h 显示帮助界面 -m 将文件压缩之后,删除源文件   -n 特定字符串 ...

  2. Linux下的常见压缩解压缩命令

    Linux常见压缩解压缩命令 常见压缩文件扩展名 .Z compress 程序压缩的文件: .zip zip 程序压缩的文件: .gz gzip 程序压缩的文件: .bz2 bzip2 程序压缩的文件 ...

  3. Linux的压缩/解压缩文件处理 zip & unzip

    Linux的压缩/解压缩命令详解及实例 压缩服务器上当前目录的内容为xxx.zip文件 zip -r xxx.zip ./* 解压zip文件到当前目录 unzip filename.zip 另:有些服 ...

  4. linux中压缩与解压缩命令小结

    linux中压缩与解压操作非常常见,其命令参数也非常的多,这里只介绍最经常用的带打包文件的几种压缩和解压方式和几个最常用的参数. 现在最常用的压缩和解压工具是gzip和bzip2,这两种工具不能相互解 ...

  5. Linux基础知识第九讲,linux中的解压缩,以及软件安装命令

    目录 Linux基础知识第九讲,linux中的解压缩,以及软件安装命令 一丶Linux Mac Windows下的压缩格式简介 2.压缩以及解压缩 3.linux中的软件安装以及卸载 1.apt进行安 ...

  6. Linux常用命令(第二版) --压缩解压缩命令

    压缩解压缩命令: ----------.gz---------- 1.压缩 gzip[GNU zip]: /bin/gzip 格式: gzip 选项 [文件] #压缩文件,压缩后扩展名为.gz,Lin ...

  7. linux中的 tar命令的 -C 参数,以及其它一些参数(转)

    linux中的 tar命令的 -C 参数,以及其它一些参数 复制源:http://www.cnblogs.com/li-hao/archive/2011/10/03/2198480.htmltar命令 ...

  8. Linux中许多常用命令是必须掌握的,这里将我学linux入门时学的一些常用的基本命令分享给大家一下,希望可以帮助你们。

    Linux中许多常用命令是必须掌握的,这里将我学linux入门时学的一些常用的基本命令分享给大家一下,希望可以帮助你们. 这个是我将鸟哥书上的进行了一下整理的,希望不要涉及到版权问题. 1.显示日期的 ...

  9. linux中神奇的命令alias

    在linux中大家应该都知道,有些命令和参数特别繁琐,而且还是大量输入这些命令,这个时候我们就可以使用linux中的alias命令来给这些繁琐的命令起别名,但是,alias 命令只对当前终端有效,当终 ...

随机推荐

  1. RChain的一键形式化验证:关于RCast 33 – LADL话题的讨论摘要

    作者/Atticbee 在这一集,Greg和RChain的研究人员Isaac,Christian讨论了TLA(Temporal Logic of Actions)和RChain的LADL(Logic ...

  2. Firebase REST API

    use firebase and firesharp to do a Library management system . look github.com/ziyasal/FireSharp

  3. 第二次作业hzw

    第二次作业 | GIT地址 | 地址链接 | |--|--| |GIT用户名 | BRYANT333 | |学号后五位|24240| |博客地址|我的博客| |作业链接|第二次作业地址| 一.环境配置 ...

  4. 解决 C# GetPixel 和 SetPixel 效率问题(转)

    在对Bitmap图片操作的时候,有时需要用到获取或设置像素颜色方法:GetPixel 和 SetPixel, 如果直接对这两个方法进行操作的话速度很慢,这里我们可以通过把数据提取出来操作,然后操作完在 ...

  5. Spring中的BeanPostProcessor详解

    Spring中的BeanPostProcessor详解 概述 BeanPostProcessor也称为Bean后置处理器,它是Spring中定义的接口,在Spring容器的创建过程中(具体为Bean初 ...

  6. UML--->活动图梳理

    活动图梳理 活动图 概述 活动图是UML用于对系统的动态行为建模的另一种常用工具,它描述活动的顺序,展现从一个活动到另一个活动的控制流,常常用于描述业务过程和并行处理过程,活动图在本质上是一种流程图. ...

  7. P4语言环境安装(一)前端编译器p4c、后端编译器p4c-bm2-ss

    这个P4安装环境是在2020-2-8安装的,安装环境卡了我好几天,把遇到的问题记录下来,有需要的同学可以参考一下,要是说错了或者有问题的话,评论或mail:guidoahead@163.com联系我都 ...

  8. 五、Django学习之基于对象的跨表查询

    五.Django学习之基于对象的跨表查询 正向与反向查询 关键在于ForeignKey字段写的位置.例如下面这段代码, 关系属性(字段)写在哪个类(表)里面,从当前类(表)的数据去查询它关联类(表)的 ...

  9. MD5加密解密以及设置salt(盐值)

    MD5算法 package com.oracle.jsp.util; import java.security.MessageDigest; import java.security.NoSuchAl ...

  10. C++ STL IO流 与 Unicode (UTF-16 UTF-8) 的协同工作

    09年研究技术的大神真的好多,本文测试有很多错误,更正后发布下(可能与编辑器相关). file.imbue(locale(file.getloc(), new codecvt_utf8<wcha ...