压缩:gzip/gunzip、bzip2/bunzip2、xz/unxz

归档:tar

归档+压缩:zip


1. gzip, gunzip, zcat - compress or expand files

gzip:压缩(压缩后会删除原文件)

gunzip:解压缩(解压缩后会删除原压缩文件)

zcat:直接查看压缩后的文本文件内容(建议不要查看大文件)

说明:

gzip、gunzip均可以同时操作多个文件

gzip、gunzip压缩/解压缩文件支持通配符

gzip、gunzip不能操作目录。

SYNOPSIS

gzip [OPTIONS] <file ...>

OPTIONS


-d --decompress --uncompress
Decompress(解压缩).
gzip -d <file> 相当于gunzip <file> -# --fast --best
指定压缩比(默认压缩比为6,建议无特殊需求不要改变默认压缩比) -c --stdout --to-stdout
将压缩结果输出至标准输出
gzip <file> 相当于 gzip -c <file> > <file.gz>(输出重定向)

EXAMPLES

[root@VM_0_171_centos tmp]# ls -lh
总用量 16K
-rw-r--r-- 1 root root 13K 4月 4 23:43 sentinel.log
[root@VM_0_171_centos tmp]# gzip sentinel.log
[root@VM_0_171_centos tmp]# ls -lh
总用量 4.0K
-rw-r--r-- 1 root root 1.4K 4月 4 23:43 sentinel.log.gz
[root@VM_0_171_centos tmp]# gzip -d sentinel.log.gz
[root@VM_0_171_centos tmp]# ls -lh
总用量 16K
-rw-r--r-- 1 root root 13K 4月 4 23:43 sentinel.log
[root@VM_0_171_centos tmp]#

2. bzip2/bunzip2/bzcat

bzip2:压缩(压缩后会删除原文件)

bunzip2:解压缩(解压缩后会删除原压缩文件)

bzcat:直接查看压缩后的文本文件内容(建议不要查看大文件)

SYNOPSIS

bzip2 [OPTIONS] <file ...>

** OPTIONS**

-d:解压缩
-#:指定压缩比;默认是6;数字越大压缩比越大(1-9);
-k:keep,保留原文件;

** EXAMPLES**

[root@VM_0_171_centos tmp]# ls -lh
总用量 16K
-rw-r--r-- 1 root root 13K 4月 4 23:43 sentinel.log
[root@VM_0_171_centos tmp]# bzip2 sentinel.log
[root@VM_0_171_centos tmp]# ls -lh
总用量 4.0K
-rw-r--r-- 1 root root 1.5K 4月 4 23:43 sentinel.log.bz2
[root@VM_0_171_centos tmp]# bzip2 -d sentinel.log.bz2
[root@VM_0_171_centos tmp]# ls -lh
总用量 16K
-rw-r--r-- 1 root root 13K 4月 4 23:43 sentinel.log
[root@VM_0_171_centos tmp]# bzip2 -k sentinel.log
[root@VM_0_171_centos tmp]# ls -lh
总用量 20K
-rw-r--r-- 1 root root 13K 4月 4 23:43 sentinel.log
-rw-r--r-- 1 root root 1.5K 4月 4 23:43 sentinel.log.bz2
[root@VM_0_171_centos tmp]#

3. xz/unxz/xzcat

用法与bzip2基本相同,但这种格式不是很常见

SYNOPSIS

xz [option]...  [file]...

** OPTIONS**

-d:解压缩
-#:指定压缩比;默认是6;数字越大压缩比越大(1-9);
-k:keep,保留原文件;

** EXAMPLES**

[root@VM_0_171_centos tmp]# ls -lh
总用量 16K
-rw-r--r-- 1 root root 13K 4月 4 23:43 sentinel.log
[root@VM_0_171_centos tmp]# xz sentinel.log
[root@VM_0_171_centos tmp]# ls -lh
总用量 4.0K
-rw-r--r-- 1 root root 1.3K 4月 4 23:43 sentinel.log.xz
[root@VM_0_171_centos tmp]# xz -d sentinel.log.xz
[root@VM_0_171_centos tmp]# ls -lh
总用量 16K
-rw-r--r-- 1 root root 13K 4月 4 23:43 sentinel.log
[root@VM_0_171_centos tmp]# xz -k sentinel.log
[root@VM_0_171_centos tmp]# ls -lh
总用量 20K
-rw-r--r-- 1 root root 13K 4月 4 23:43 sentinel.log
-rw-r--r-- 1 root root 1.3K 4月 4 23:43 sentinel.log.xz
[root@VM_0_171_centos tmp]#

4. tar - manual page for tar 1.26

归档文件或目录

SYNOPSIS

tar [OPTION...] [FILE]...

OPTIONS

#创建归档(v选项用于显示执行过程)
tar -cvf /PATH/TO/file.tar <file ...>
#创建归档并压缩成.gz格式
tar -zcvf /PATH/TO/file.tar <file ...>
#创建归档并压缩成.bz2格式
tar -jcvf /PATH/TO/file.tar <file ...> #展开归档
tar -xvf <file ...> [-C <展开至目标目录>]
#解压并展开归档(.gz)
tar -zxvf <file ...> [-C <展开至目标目录>]
#解压并展开归档(.bz2)
tar -jxvf <file ...> [-C <展开至目标目录>] #查看归档文件的文件列表
tar -tf <file>

EXAMPLES

下载nginx-1.10.3.tar.gz,解压,再压缩成.bz2格式

[root@VM_0_171_centos tmp]# ls
sentinel.log sentinel.log.xz
[root@VM_0_171_centos tmp]# wget http://nginx.org/download/nginx-1.10.3.tar.gz
--2017-04-11 22:44:56-- http://nginx.org/download/nginx-1.10.3.tar.gz
正在解析主机 nginx.org (nginx.org)... 206.251.255.63, 95.211.80.227, 2606:7100:1:69::3f, ...
正在连接 nginx.org (nginx.org)|206.251.255.63|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:911509 (890K) [application/octet-stream]
正在保存至: “nginx-1.10.3.tar.gz” 100%[=========================================================>] 911,509 445KB/s 用时 2.0s 2017-04-11 22:44:59 (445 KB/s) - 已保存 “nginx-1.10.3.tar.gz” [911509/911509]) [root@VM_0_171_centos tmp]# ls
nginx-1.10.3.tar.gz sentinel.log sentinel.log.xz
[root@VM_0_171_centos tmp]# tar -jcf nginx-1.10.3.tar.bz2 nginx-1.10.3
[root@VM_0_171_centos tmp]# ls
nginx-1.10.3 nginx-1.10.3.tar.bz2 nginx-1.10.3.tar.gz sentinel.log sentinel.log.xz
[root@VM_0_171_centos tmp]#

5.zip - package and compress (archive) files

最通用的压缩、打包工具

用法

zip file.zip <file ...>
unzip -d <解压目录> <file>

EXAMPLES

[root@VM_0_171_centos tmp]# ls
nginx-1.10.3 sentinel.log sentinel.log.xz
[root@VM_0_171_centos tmp]# zip nginx-1.10.3.zip nginx-1.10.3/
adding: nginx-1.10.3/ (stored 0%)
[root@VM_0_171_centos tmp]# ls
nginx-1.10.3 nginx-1.10.3.zip sentinel.log sentinel.log.xz
[root@VM_0_171_centos tmp]# zip test.zip nginx-1.10.3 sentinel.log
adding: nginx-1.10.3/ (stored 0%)
adding: sentinel.log (deflated 89%)
[root@VM_0_171_centos tmp]# ls
nginx-1.10.3 nginx-1.10.3.zip sentinel.log sentinel.log.xz test.zip
[root@VM_0_171_centos tmp]# unzip -d ./test/ test.zip
Archive: test.zip
creating: ./test/nginx-1.10.3/
inflating: ./test/sentinel.log
[root@VM_0_171_centos tmp]# ls
nginx-1.10.3 nginx-1.10.3.zip sentinel.log sentinel.log.xz test test.zip
[root@VM_0_171_centos tmp]#

Linux-压缩与归档的更多相关文章

  1. linux 压缩和归档

    在linux下有几种压缩方式:gzip.bzip2.xz.zip gzip 压缩文件以.gz结尾, 只能压缩文件,不能压缩目录 用法: gzip:/path/to/somefile   用来压缩,完成 ...

  2. Linux压缩与归档

    文件的压缩     aaaaaabbbbccc压缩成为6a4b3c     压缩工具:     gzip/gunzip: .gz后缀         只能压缩文件,不能压缩目录,因其不具备归档功能   ...

  3. linux压缩及归档

    一.解析 压缩:把大文件,通过压缩成一个比之前小的文件. 归档(打包):把多个文件,归档成一个文件. 二.压缩 1.zip(归档压缩,可以压缩目录,要保存源文件) 压缩:zip  压缩后的文件名 压缩 ...

  4. Linux 文件压缩与归档

    .note-content { font-family: "Helvetica Neue", Arial, "Hiragino Sans GB", STHeit ...

  5. Linux下的压缩及归档

    Linux下常用的压缩格式有: gz,bz2,xz,zip,Z //只能压缩文件不能压缩目录,如果传递一个目录,他会把目录中的文件逐个压缩 ..压缩算法:算法不同,压缩比也不同 gz:gzip,压缩后 ...

  6. (转)linux下压缩和归档相关命令tar,zip,gzip,bzip2

    压缩包也有两种形式,一种是tar.gz包(.tgz包也是这种),一种是tar.bz2包. tar.gz包的解压方法:tar zxvf [PackageName].tar.gz tar.bz2包的解压方 ...

  7. linux 压缩、解压缩及归档工具

    linux下主要的压缩.归档工具 compress/uncompress: .Z gzip/gunzip:  .gz bzip2/bunzip2: .bz2 xz/unxz: .xz zip/unzi ...

  8. Linux压缩命令总结

    2018-02-28  10:43:18 linux压缩和解压缩命令大全 tar命令:tar本身仅是一个打包的命令,不具有压缩的功能.打包后源文件仍然存在,具有将多个文件归档成一个文件的功能[root ...

  9. Linux —— 压缩文件

    Linux——压缩文件 为什么需要压缩文件?    文件在传输过程中,可能由于文件过大,传输所需时间过多.减少文件大小有两个明显的好处,一是可以减    少存储空间,二是通过网络传输文件时,可以减少传 ...

  10. Linux 常用解压缩归档命令

    linux 常见压缩.归档工具 创建压缩工具 压缩工具 后缀 描述 compress/uncompress .Z 早期工具,现在不常见了 gzip/gunzip .gz 进几年比较火的工具 bzip2 ...

随机推荐

  1. centos7中输入ifconfig出现ens33,没有eth0(转)

    vmware安装的centos7中没有出现eth0网卡,也没有ip,不能上网,输入ifconfig后如下图 解决办法 1.编辑网卡的配置文件 vi /etc/sysconfig/network-scr ...

  2. swift 属性值变化

    如果创建了一个结构体的实例并将其赋值给一个常量,则无法修改该实例的任何属性,即使有属性被声明为变量也不行. 这种行为是由于结构体(struct)属于值类型.当值类型的实例被声明为常量的时候,它的所有属 ...

  3. tomcat与jmeter

    jmeter无法提取出Tomcat之外的其他服务器的指标. 为了克服这一现状,研发了一个服务器代理,jmeter通过这个代理来获取性能数据. 代理使用的是sigar开源库,他是一个java通过部分和一 ...

  4. .net判断当前时间是否在工作时间段内

    整理代码,判断当前时间是否在配置的工作时间段内,代码如下: public static bool getTimeSpan(string _strWorkingDayAM, string _strWor ...

  5. php实现MySQL两库对比升级版

    define('DATABASE1', 'db1'); $dbi1 = new DbMysql; $dbi1->dbh = 'mysql://root:password@127.0.0.1/'. ...

  6. Linux mount命令

    mount 1.作用 mount命令的作用是加载文件系统,它的用权限是超级用户或/etc/fstab中允许的使用者. 2.格式 mount -a [-fv] [-t vfstype] [-n] [-r ...

  7. Django框架之Ajax和form组件

    一.Django框架之查漏补缺 1)models,字段概况 name = models.CharField(max_length=) age = models.IntegerField() price ...

  8. oracle 导出表

    由于进项目组是跟着dba做事情的,但是没做多久dba走了,差不多就把数据库方面的“杂事”接下来了. 小白一个,只有敬小慎微的操作.经常看到的高水位和低水位的情况,也不敢去乱动. 搞好今天晚上需要跑数据 ...

  9. vue属性值调方法

    <td>{{showPrice(product.sellprice)}}</td>

  10. Educational Codeforces Round 62 E 局部dp + 定义状态取消后效性

    https://codeforces.com/contest/1140/problem/E 局部dp + 定义状态取消后效性 题意 给你一个某些位置可以改变的字符串,假如字符串存在回文子串,那么这个字 ...