gzip压缩工具

1.将etc下的所有conf文件查看后循环追加到1.txt文件中

[root@bogon gzip]# find /etc/ -type f -name '*.conf' -exec cat {} >> 1.txt \;
[root@bogon gzip]# ls
1.txt

2.用gzip进行压缩后

[root@bogon gzip]# ll -sh 1.txt
628K -rw-r--r-- 1 root root 628K 12月 26 09:18 1.txt
[root@bogon gzip]# wc -l 1.txt
18297 1.txt
[root@bogon gzip]# gzip 1.txt
[root@bogon gzip]# ll -h 1.txt.gz
-rw-r--r-- 1 root root 166K 12月 26 09:18 1.txt.gz
[root@bogon gzip]#

3.gzip -d 或 gunzip  解压的文件名

[root@bogon gzip]# gzip -d 1.txt.gz
[root@bogon gzip]# du -sh 1.txt
628K 1.txt
[root@bogon gzip]#

4.gzip -(1-9) 指定压缩级别,用 -1 压缩后变为196k ,-9是压缩比最大的 默认是-6级别。

[root@bogon gzip]# du -sh 1.txt
628K 1.txt
[root@bogon gzip]# gzip -1 1.txt
[root@bogon gzip]# du -sh 1.txt.gz
196K 1.txt.gz
[root@bogon gzip]#

5.用gzip -9 压缩一下试试,变成了168k

[root@bogon gzip]# gzip -9 1.txt
[root@bogon gzip]# du -sh 1.txt.gz
168K 1.txt.gz
[root@bogon gzip]#

6.file命令可以查看压缩文件信息

[root@bogon gzip]# file 1.txt.gz
1.txt.gz: gzip compressed data, was "1.txt", from Unix, last modified: Tue Dec 26 09:18:00 2017, max compression
[root@bogon gzip]#

7.zcat 命令可以查看压缩文件内容

8.压缩文件指定到一个目录下,并且原文件不消失。

[root@bogon gzip]# gzip -c 1.txt > /tmp/1.txt.gz
[root@bogon gzip]# ll
总用量 628
-rw-r--r-- 1 root root 642394 12月 26 09:18 1.txt
[root@bogon gzip]# ls /tmp/1.txt.gz
/tmp/1.txt.gz
[root@bogon gzip]#

9.解压文件同样也可以指定目录

[root@bogon gzip]# gzip -d -c /tmp/1.txt.gz > /tmp/gzip/2.txt
[root@bogon gzip]# ls
1.txt 2.txt
[root@bogon gzip]#

10.查看文件大小和行数

[root@bogon gzip]# wc -l 1.txt 2.txt
18297 1.txt
18297 2.txt
36594 总用量
[root@bogon gzip]# du -sh 1.txt 2.txt
628K 1.txt
628K 2.txt
[root@bogon gzip]#

11.gzip 不能压缩目录

bzip2压缩工具

1.bzip2比gzip压缩的更狠

[root@bogon bzip2]# bzip2 1.txt
[root@bogon bzip2]# du -sh 1.txt.bz2
152K 1.txt.bz2
[root@bogon bzip2]#

2.解压使用bzip2 -d 或者 bunzip2  1.txt.bz2 ,不支持压缩目录,支持-c 指定压缩到某个目录

[root@bogon bzip2]# bzip2 -d 1.txt.bz2
[root@bogon bzip2]# ll
总用量 628
-rw-r--r-- 1 root root 642394 12月 26 15:19 1.txt
[root@bogon bzip2]#
[root@bogon bzip2]# bzip2 -c 1.txt > /tmp/1.txt.bz2
[root@bogon bzip2]# du -sh /tmp/1.txt.bz2
152K /tmp/1.txt.bz2
[root@bogon bzip2]#

3.支持 -d -c 选项

[root@bogon bzip2]# bzip2 -d -c /tmp/1.txt.bz2 > 3.txt
[root@bogon bzip2]# ls
1.txt 3.txt
[root@bogon bzip2]#

4.bzip2也有压缩级别,默认的压缩级别就是9

5.bzcat 也是查看压缩文件内容的。

xz压缩工具

1.xz压缩工具压缩比比bzip2更狠不支持压缩目录

2.xz 文件名

[root@bogon xz]# xz 1.txt
[root@bogon xz]# ls
1.txt.xz
[root@bogon xz]# ll
总用量 144
-rw-r--r-- 1 root root 144124 12月 26 16:14 1.txt.xz
[root@bogon xz]# du -sh 1.txt.xz
144K 1.txt.xz
[root@bogon xz]#

3.用xz -d或unxz 解压缩

[root@bogon xz]# xz -d 1.txt.xz
[root@bogon xz]# ls
1.txt
[root@bogon xz]#

4.支持 -d -c

[root@bogon xz]# ls
1.txt
[root@bogon xz]# xz -c 1.txt > /tmp/2.txt.xz
[root@bogon xz]# xz -d -c /tmp/2.txt.xz > ./2.txt
[root@bogon xz]# ll
总用量 1256
-rw-r--r-- 1 root root 642394 12月 26 16:14 1.txt
-rw-r--r-- 1 root root 642394 12月 26 16:18 2.txt
[root@bogon xz]#

5.可以用xzcat查看压缩包内容

zip压缩工具

1.cp -r 功能上是等价的。不加-r或者-R的时候,只拷贝文件,不拷贝文件夹;加上后则会拷贝文件夹——包括下一级的子文件夹,以及子文件夹中的子文件夹,余此类推。

2.zip压缩文件,保留文件不删除

[root@bogon zip]# zip 1.txt.zip 1.txt
adding: 1.txt (deflated 74%)
[root@bogon zip]# ll
总用量 796
-rw-r--r-- 1 root root 642394 12月 26 18:06 1.txt
-rw-r--r-- 1 root root 170088 12月 27 09:25 1.txt.zip
[root@bogon zip]#

3.zip压缩目录和文件

[root@bogon tmp]# zip -r gzip.zip dnsmasq.txt gzip
adding: dnsmasq.txt (deflated 64%)
adding: gzip/ (stored 0%)
adding: gzip/1.txt (deflated 74%)
adding: gzip/2.txt (deflated 74%)
[root@bogon tmp]#
[root@bogon tmp]# ll *.zip
-rw-r--r-- 1 root root 349639 12月 27 09:37 gzip.zip
[root@bogon tmp]#

4.unzip 减压zip压缩包

[root@bogon tmp]# unzip gzip.zip
Archive: gzip.zip
replace dnsmasq.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: A
inflating: dnsmasq.txt
inflating: gzip/1.txt
inflating: gzip/2.txt
[root@bogon tmp]#

5.将文件减压到test目录

[root@bogon tmp]# unzip gzip.zip -d test/
Archive: gzip.zip
inflating: test/dnsmasq.txt
creating: test/gzip/
inflating: test/gzip/1.txt
inflating: test/gzip/2.txt
[root@bogon tmp]#

6.zip没有zipcat命令,可以用unzip -l 查看文件列表

[root@bogon tmp]# unzip -l gzip.zip
Archive: gzip.zip
Length Date Time Name
--------- ---------- ----- ----
25194 12-22-2017 17:49 dnsmasq.txt
0 12-26-2017 14:16 gzip/
642394 12-26-2017 09:18 gzip/1.txt
642394 12-26-2017 14:16 gzip/2.txt
--------- -------
1309982 4 files
[root@bogon tmp]#

tar打包 

1.tar c创建 v可视化 f后面跟打包成什么

[root@bogon tar]# tar cvf zip.tar zip/
zip/
zip/1.txt
zip/1.txt.zip
zip/gzip/
zip/gzip/1.txt
zip/gzip/2.txt
[root@bogon tar]#

2.解包用xvf 从档案文件中释放文件

[root@bogon tar]# tar -xvf zip.tar
zip/
zip/1.txt
zip/1.txt.zip
zip/gzip/
zip/gzip/1.txt
zip/gzip/2.txt
[root@bogon tar]# ll
总用量 2060
drwxr-xr-x 3 root root 45 12月 27 10:02 zip
-rw-r--r-- 1 root root 2109440 12月 27 10:07 zip.tar
[root@bogon tar]#

3.tar可以目录文件一起打包

[root@bogon tar]# tar -cvf zip.tar zip 1.txt 2.txt
zip/
zip/gzip/
zip/gzip/1.txt
zip/gzip/2.txt
zip/1.txt
zip/1.txt.zip
1.txt
2.txt
[root@bogon tar]#

4.tar -tf 可以查看包文件列表

[root@bogon tar]# tar -tf zip.tar
zip/
zip/gzip/
zip/gzip/1.txt
zip/gzip/2.txt
zip/1.txt
zip/1.txt.zip
1.txt
2.txt
[root@bogon tar]#

5.--exclude 指定打包时不包含的目录

[root@bogon tar]# tar -tf zip.tar
zip/
zip/gzip/
zip/gzip/1.txt
zip/gzip/2.txt
zip/1.txt
zip/1.txt.zip
1.txt
2.txt
[root@bogon tar]# tar -cvf zip.tar --exclude gzip zip 1.txt 2.txt
zip/
zip/1.txt
zip/1.txt.zip
1.txt
2.txt
[root@bogon tar]#

6.--exclude 可以写多个不包含*.txt

[root@bogon tar]# tar -cvf zip.tar --exclude gzip --exclude "*.txt" zip 1.txt 2.txt
zip/
zip/1.txt.zip
[root@bogon tar]#

7.tar打包并压缩成gz格式tar -zcvf

[root@bogon tar]# tar -zcvf zip.tar.gz zip
zip/
zip/gzip/
zip/gzip/1.txt
zip/gzip/2.txt
zip/1.txt
zip/1.txt.zip
[root@bogon tar]# du -sh zip.tar.gz
664K zip.tar.gz
[root@bogon tar]#

8.支持bz2

[root@bogon tar]# tar -jcvf zip.tar.bz2 zip
zip/
zip/gzip/
zip/gzip/1.txt
zip/gzip/2.txt
zip/1.txt
zip/1.txt.zip
[root@bogon tar]#

9.支持xz压缩

[root@bogon tar]# tar -Jcvf zip.tar.xz zip
zip/
zip/gzip/
zip/gzip/1.txt
zip/gzip/2.txt
zip/1.txt
zip/1.txt.zip
[root@bogon tar]# du -sh zip.tar.xz
308K zip.tar.xz
[root@bogon tar]#

  

Linux文件压缩和打包的更多相关文章

  1. Linux文件压缩与打包笔记

    linux 文件压缩与打包笔记 压缩原理:通过算法去掉空位,1Bytes=8bits , 可能存储的真正有用的数据并没有占满一个字节空间 , 还有就是可能有重复的数据,通过某种算法从这些方面进行压缩处 ...

  2. linux文件压缩与打包

    在linux中常见的压缩命令 首先,在linux中压缩文件的扩展名大多是 *.gz gzip程序压缩的文件 *.bz2 bzip2程序压缩的文件 *.tar tar程序打包的数据,并没有压缩过 *.t ...

  3. Linux 文件压缩、打包

    文件压缩 计算机使用byte单位来计量.实际上,计算机最小的计量单位是bit.1byte = 8 bit.如果记录1这个数字,00000001,1会在最右边占一个1个bit 其他7个bit会被填上0. ...

  4. Linux文件压缩、打包、备份

    1:Linux常见的压缩文件 2:gzip压缩指令 3:bzip2压缩指令(比gzip更高压缩比) 同理,可以用bzcat\bzmore\bzless读取被压缩后文件内容. 4:xz压缩指令(比bzi ...

  5. 10.18.2 linux文件压缩与打包

    tar压缩工具 tar 本身为一个打包工具,可以把目录打包成一个文件,它的好处是它把所有文件整合成一个大文件整体,方便拷贝或者移动. 语法:tar [-zjxcvfpP] filename tar 命 ...

  6. Linux系统下文件压缩与打包命令

    Linux系统下文件压缩与打包命令 常用的压缩文件拓展名 * .Z * .zip * .gz * .bz2 * .xz * .tar * .tar.gz * .tar.bz2 * .tar.xz 压缩 ...

  7. linux文件压缩与文件夹压缩(打包)

    目录 一:linux文件压缩 1.linux常见的压缩包有哪些? 2.bzip压缩(文件) 二:打包(文件夹压缩) 1.打包命令 2.参数 3.参数解析(实战) 4.注意事项 简介: win中的压缩包 ...

  8. Linux 文件压缩与归档

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

  9. Linux文件压缩和解压缩命令

    Linux文件压缩和解压缩命令: tar 命令(打包并压缩的话,原文件也会默认存在) -c 建立打包档案 -x 解包 -t 查看包里的类容 -r 向包里追加文件 -v 显示打包过程 -f 文件 比如: ...

随机推荐

  1. ThreadPoolExecutor(线程池)源码分析

    1. 常量和变量 private final AtomicInteger ctl = new AtomicInteger(ctlOf(RUNNING, 0)); // 高3位为线程池的运行状态,低29 ...

  2. 关于热插拔usb hotplug /proc/sys/kernel mdev udev b...

    转:http://www.360doc.com/content/10/0527/18/9922_29835045.shtml 这篇文章说的很好http://blog.chinaunix.net/u1/ ...

  3. 可添加头部尾部RecyclerView,很帅哦~

    WrapRecyclerView 是一个可以添加头部和尾部的RecyclerView,并且提供了一个 WrapAdapter, 它可以让你轻松为 RecyclerView 添加头部和尾部.   示例中 ...

  4. redis_常用命令

    一.启动redis客户端 cmd   cd D:\Project\redis-2.8.17   redis-cli.exe     二.常用命令   参考文档:http://redisdoc.com/ ...

  5. AS3.0 效率优化

    1.显示对象:1.1.静态的不需互动的图形,使用Shape对象.(eg:getSize(newShape())=236) 1.2.不需要时间轴的互动图形,使用Sprite对象.(eg:getSize( ...

  6. Spring WebSocket入门(一) 转载

    本文转载自:http://www.jianshu.com/p/60799f1356c5 WebSocket是html5带来的一项重大的特性,使得浏览器与服务端之间真正长连接交互成为了可能,这篇文章会带 ...

  7. [转]在SSIS中,使用“包配置”时的常见错误与解析

    本文转自:http://www.cnblogs.com/invinboy/archive/2008/05/26/1034312.html 在以前的DTS中,在包的开发.测试.发布迁移过程中你必须手动的 ...

  8. c/c++的|、||、&、&&、异或、~、!运算

    位运算     位运算的运算分量只能是整型或字符型数据,位运算把运算对象看作是由二进位组成的位串信息,按位完成指定的运算,得到位串信息的结果. 位运算符有:     &(按位与).|(按位或) ...

  9. My97DatePicker日历控件配置

    一. 简介 1. 简介 目前的版本是:4.72 2. 注意事项 My97DatePicker目录是一个整体,不可破坏里面的目录结构,也不可对里面的文件改名,可以改目录名 My97DatePicker. ...

  10. SQL Server CPU时间和占用时间及优化

    如何测试sql语句执行时间 在MSSQL Server中通过查看SQL语句执行所用的时间,来衡量SQL语句的性能. set statistics profile on set statistics i ...