Linux文件压缩和打包
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文件压缩和打包的更多相关文章
- Linux文件压缩与打包笔记
linux 文件压缩与打包笔记 压缩原理:通过算法去掉空位,1Bytes=8bits , 可能存储的真正有用的数据并没有占满一个字节空间 , 还有就是可能有重复的数据,通过某种算法从这些方面进行压缩处 ...
- linux文件压缩与打包
在linux中常见的压缩命令 首先,在linux中压缩文件的扩展名大多是 *.gz gzip程序压缩的文件 *.bz2 bzip2程序压缩的文件 *.tar tar程序打包的数据,并没有压缩过 *.t ...
- Linux 文件压缩、打包
文件压缩 计算机使用byte单位来计量.实际上,计算机最小的计量单位是bit.1byte = 8 bit.如果记录1这个数字,00000001,1会在最右边占一个1个bit 其他7个bit会被填上0. ...
- Linux文件压缩、打包、备份
1:Linux常见的压缩文件 2:gzip压缩指令 3:bzip2压缩指令(比gzip更高压缩比) 同理,可以用bzcat\bzmore\bzless读取被压缩后文件内容. 4:xz压缩指令(比bzi ...
- 10.18.2 linux文件压缩与打包
tar压缩工具 tar 本身为一个打包工具,可以把目录打包成一个文件,它的好处是它把所有文件整合成一个大文件整体,方便拷贝或者移动. 语法:tar [-zjxcvfpP] filename tar 命 ...
- Linux系统下文件压缩与打包命令
Linux系统下文件压缩与打包命令 常用的压缩文件拓展名 * .Z * .zip * .gz * .bz2 * .xz * .tar * .tar.gz * .tar.bz2 * .tar.xz 压缩 ...
- linux文件压缩与文件夹压缩(打包)
目录 一:linux文件压缩 1.linux常见的压缩包有哪些? 2.bzip压缩(文件) 二:打包(文件夹压缩) 1.打包命令 2.参数 3.参数解析(实战) 4.注意事项 简介: win中的压缩包 ...
- Linux 文件压缩与归档
.note-content { font-family: "Helvetica Neue", Arial, "Hiragino Sans GB", STHeit ...
- Linux文件压缩和解压缩命令
Linux文件压缩和解压缩命令: tar 命令(打包并压缩的话,原文件也会默认存在) -c 建立打包档案 -x 解包 -t 查看包里的类容 -r 向包里追加文件 -v 显示打包过程 -f 文件 比如: ...
随机推荐
- http请求 url 传递参数(特殊字符)解决方法
有些符号在URL中是不能直接传递的,如果要在URL中传递这些特殊符号,那么就要使用他们的编码了.下表中列出了一些URL特殊符号及编码 十六进制值 1. + URL 中+号表示空格 %2B ...
- [典型漏洞分享]exported Android content provider引发的隐私泄露问题
YS android手机APP对外开放多余的content provider,可任意增.删.改和查images数据库表格,导致隐私泄露 问题描述: YS android手机APP使用SQLITE数据库 ...
- System.Object 基类
System.Object在.Net中是所有类型的基类,任何类型都直接或间接地继承自System.Object.没有指定基类的类型都默认继承于System.Object. 基类特性 正由于所有的类型都 ...
- Git 对比 SVN
转自:http://www.aqee.net/5-fundamental-differences-between-git-svn/ 我是一开始就用Mercurial, Git这类的系统.(现在已经百分 ...
- Windows环境下32位汇编语言程序设计(典藏版)
<Windows环境下32位汇编语言程序设计(典藏版) > 基本信息 作者: 罗云彬 出版社:电子工业出版社 ISBN:9787121207594 上架时间:2013-7-8 出版日期:2 ...
- linux下使用C++ Json库
安装Json库 1.下载JsonCpphttp://sourceforge.net/projects/jsoncpp/files/ 2.下载sconshttp://sourceforge.net/pr ...
- 两款工控控件对比评测:Iocomp和ProEssentials
对于程序员来说,要凭一己之力开发出漂亮逼真的工控仪表和工控图表是非常耗时间和精力的,那么使用专业的第三方控件就是不错的选择,不仅节约开发时间,降低了项目风险,最重要的是第三方控件写的程序更专业,工控图 ...
- Dev之ribbon设置
- screen space shadowmap unity
unity用到了screen space shadow map 1.camera 在light pos 生成depth1 2.screen space depth2 3.根据depth1 depth2 ...
- 3dsMAX 插件
SDK C++ 对性能有要求 底层接口 MAXScript 上层接口 a few more function whick sdk does not afford MCG像蓝图一样的东西 http:// ...