压缩: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. VS Installer教程

    本文主要讲解利用VS2010下的Visual Studio Installer打包Zigbee程序(VS2010编写)的过程. 1.打开Zigbee程序,在解决方案中添加“新建项目”-->其他项 ...

  2. JSP脚本元素(声明 %! 表达式 %= 脚本 %)

    JSP脚本元素包括声明.表达式.脚本 声明(declaration):用于在JSP页面中声明合法的变量和方法.以“<%!”开始,以“%>”结束. 在JSP页面中,一个声明可以出现在任何地方 ...

  3. rm命令删除文件时排除特定文件

    删除文件时排除特定文件 www.python  tab.com/html/2013/linuxkaiyuan_0205/214.html 删除当前目录下所有 *.txt文件,除了test.txt 1 ...

  4. NETSHARP的JAVA开发环境配置

    一:JAVA配置 1. netsharp使用java1.8/1.7版本,本文使用1.8版本 2.jdk下载地址:http://www.oracle.com/technetwork/java/javas ...

  5. mysql 压缩版安装

    环境介绍:win2008_x64+mysql5.7.10  64位 1.将压缩包解压到d:\\mysql目录,并将mysql目录中的my-default.ini 重命名为my.ini 2.将my.in ...

  6. maven下的jar项目打包的方法

    1.先对pom项目进行install: RunAs->maven install,如果出现如下错误: Failed to execute goal org.apache.maven.plugin ...

  7. Flex 确定弹出窗口的绝对位置x , y

    var selectbox:Selectbox; selectbox = new SelectBox(); var pt:Point = new Point(0,0); pt = this.paren ...

  8. 过河卒(NOIP2002)

    题目链接:过河卒 直接模拟?会T掉60分. 所以我们可以采用递推,怎么想到的? 因为卒子只能向下或向右走,所以走到一个点的方法数,等于走到它上面点的方法数加上走到它左边点的方法数,这样就可以地推了. ...

  9. 《团队-爬取豆瓣电影TOP250-设计文档》

    搭建环境: 1.安装python3.4 2.安装pycharm集成开发环境 3.安装Git for Windows 4.安装python第三方包 bs4开发阶段: 1.团队成员申请并配置github账 ...

  10. oracle 查看表行数所占空间大小

    最新数据库空间有感觉捉急了,上次,删了些数据空了800+G,撑了一个多月,现在还有400+G,每天10G的增量,多少空间也感觉不够用啊. 不能加硬盘,就只有删数据了.. 删数据,人懒,直接找表行最多, ...