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 文件 比如: ...
随机推荐
- 使用create-react-app时的something is already running on port 3000
问题: 自己今天在使用create-react-app搭建react应用的时候,开启了两个React app,然后npm start的时候,出现something is already running ...
- React的思想
react是什么 react是开发出来用来促进UI交互的,创建带有状态的.可复用的UI组件的IU库 react不仅可以在浏览器端使用,还可以在服务器端使用,还可以两端一起使用. react的底层概念: ...
- Codeforces Round #344 (Div. 2) A. Interview 水题
A. Interview 题目连接: http://www.codeforces.com/contest/631/problem/A Description Blake is a CEO of a l ...
- 区块链核心技术:拜占庭共识算法之PBFT
PBFT是Practical Byzantine Fault Tolerance的缩写,意为实用拜占庭容错算法.该算法是Miguel Castro (卡斯特罗)和Barbara Liskov(利斯科夫 ...
- Android双系统实现
1. 前言: 刷机,似乎是安卓手机用户的一项专利,可是,会刷机的用户一般都是喜新厌旧的角色. 一个系统用久了.就想换到还有一个系统.或者认为没有原来的好,或者又认为要换回去.这样又要重刷. 可是刷来刷 ...
- git命令01
1.了解git工具产生的背景知识.git 是什么? 目前它是一种分布式版本控制系统.那什么又是版本控制系统? 一种能自动帮助记录每次文件的改动,不仅仅是记录自己对文件的修 改变化,而且可以记录其他人对 ...
- js 获取两位小数的方法
1. 最笨的办法 function get() { var s = 22.127456 + ""; var str = s.substring(0,s.indexOf(" ...
- 【JavaScript】DAG(有向无环图),以及相关的JS库
rappid在线设计器:http://www.jointjs.com/rappid#bc0d3f72-102b-4e6a-8663-00af78da3a2c NorthwoodsSoftware/Go ...
- 【笔记】探索js 的this 对象 (第二部分)
了解this 对象之后 我们明白了this 对象就是指向调用函数的作用域 那么接下来我们便要清除函数究竟在哪个作用域调用 找到调用的作用域首先要了解一下几点: 1.调用栈: 调用栈就是一系列的函数,表 ...
- Android 5.0 怎样正确启用isLoggable(一)__使用具体解释
isLoggable是什么 在Android源代码中,我们常常能够看到例如以下代码: //packages/apps/InCallUI/src/com/android/incallui/Log.jav ...