压缩: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. How to use external classes and PHP files in Laravel Controller?

    By: Povilas Korop Laravel is an MVC framework with its own folder structure, but sometimes we want t ...

  2. [SoapUI] 判断工程下某个文件是否存在,存在就删除

    def excelName = "AllTests-Fails" String projectPath = context.expand( '${projectDir}' ) St ...

  3. java指针与引用(转载)

    大家都知道java和C#中没有指针这个概念.但是也导致了编程中常常忽略了对象与引用的区别,难道java真的没有指针吗?句柄是什么?变量地址在哪里?没有地址是不可能的,关键是java中如何避免了指针这个 ...

  4. Continuous Subarray Sum LT523

    Given a list of non-negative numbers and a target integer k, write a function to check if the array ...

  5. jedis常用API

    一.Redis Client介绍 1.1.简介 Jedis Client是Redis官网推荐的一个面向java客户端,库文件实现了对各类API进行封装调用. Jedis源码工程地址:https://g ...

  6. install virtualenv

    $ [sudo] pip install virtualenv $ mkdir ~/envs $ virtualenv ~/envs/lsbaws/ $ cd ~/envs/lsbaws/ $ ls ...

  7. spring学习 十三 注解AOP

    spring 不会自动去寻找注解,必须告诉 spring 哪些包下的类中可能有注解,也就是要开启注解扫描,注解的包是spring-context.jar,所以在配置文件中还要引入context约束,也 ...

  8. CSS-背景-渐变-文本格式化

    1.背景 1.背景色 属性:background-color 取值:合法的颜色值 注意:背景颜色和背景图片默认都从边框位置处开始填充 2.背景图片 属性:background-image 取值:url ...

  9. day09作业—函数进阶

    # 2.写函数,接收n个数字,求这些参数数字的和.(动态传参) def func1(*args): sum = 0 for i in args: sum += i print(sum) func1(1 ...

  10. 2019.01.22 bzoj3333: 排队计划(逆序对+线段树)

    传送门 题意简述:给出一个序列,支持把ppp~nnn中所有小于等于apa_pap​的'扯出来排序之后再放回去,要求动态维护全局逆序对. 思路:我们令fif_ifi​表示第iii个位置之后比它大的数的个 ...