压缩格式
• tar 格式,归档文件,简单的将文件整合到一个文件内,无压缩效果
• gzip 格式,.tar.gz, gzip 压缩文件,不仅能整合到一个文件,同时有体积压缩效果
- ".zip"格式: Linux 、 Windows 、 MacOS ,常用
- ".7zip" : Windows 系统常用
- ".rar" : Windows 系统常用
- ".tar ": Linux 、 MacOS 常用
- ".gzip" : Linux 、 MacOS 常用
- ".bz2"
- ".gz"
一、.tar格式
1. tar命令——打包和解包
- 语法:tar [选项 ] [-f 压缩包名] 源文件或目录
- 选项
- -c ,打包
- -x ,解压
- -v ,显示压缩、解压过程,用于查看进度
- -f ,指定压缩包的文件名, -f选项必须在选项位最后一个
- -z , gzip 模式压缩,".tar.gz", -z 选项,建议在开头位置
- -j, bzip2 模式压缩,".tar.bz2",建议在开头位置
- -C,大写,指定解压的位置 C 选项单独使用,和解压的其它参数分开
- -t : 测试,查看压缩包内有哪些文件
- tar的常用组合为:
打包:
tar -cvf 1.tar
tar -zcvf 1.tar.gz
tar -jcvf 1.tar.bz2
解压:
tar -xvf
tar -zxvf 压缩包 -c 指定目录
tar -jxvf 压缩包 -c 指定目录
查看压缩包
tar -txf
压缩 #1.1.tar -cvf test.tar 1.txt 2.txt 3.txt #将多个文件压缩到test.tar文件内 #1.2.将多个文件压缩到test.tar.gz内,使用gzip模式 [test2@localhost ~]$ tar -zcvf test.tar.gz 1.txt 2.txt 3.txt 1.txt 2.txt 解压 #2.1.tar -xvf test.tar #解压test.tar,至当前目录 #2.2.tar -xvf test.tar -C /home/itheima #解压test.tar 至指定目录 #2.3. Gzip模式解压test.tar.gz,至指定目录 [test2@localhost ~]$ tar -zxvf test.tar.gz -C ~/testtar 1.txt 2.txt 3.txt
二、.zip格式
1. zip命令——压缩文件或目录
语法:zip [-r] 压缩包名 源文件或源目录
zip:package andcompare files
选项:• -r ,压缩目录
zip test.zip a.txt b.txt c.txt #将a.txt b.txt c.txt 压缩到 test.zip 文件内 zip -r test.zip test itheima a.txt #将test、 itheima 文件夹和 a.txt 文件,压缩到 test.zip 文件
2. unzip命令——.zip的解压命令
语法:unzip [-d] 压缩包名
选项:• -d,指定解压去的目录 ,同 tar 的 -C 选项
unzip test.zip,将test.zip 解压到当前目录 unzip test.zip -d /home/itheima ,将 test.zip 解压到指定文件夹
三、.gz格式
1. gzip命令——压缩文件或目录
- 语法:gzip [选项] 源文件或源目录
- zip:package andcompare files
- 选项:
- -r ,压缩目录
- -c ;将压缩数据输出到标准输出中,可以用于保留源文件
- -d:解压缩
- -v:显示压缩文件信息
- -数字:用于指定压缩等级,默认-6,-1压缩比最低,-9压缩比最高
#基本压缩:压缩文件生成,源文件消失 [root@localhost test2]# gzip linux.txt [root@localhost test2]# ls linux.txt.gz test1 test2 test3 test4 #保留源文件压缩 [root@localhost test2]# gzip -c linux.txt > linux.txt.gz #目录不会打包,目录下子文件分别压缩 [root@localhost test2]# gzip -r test/
2. gzip -d 和 gunzip命令——.gz的解压命令
语法:gzip -d 压缩包
语法:gunzip 压缩包
语法:zcat 纯文本压缩包:查看压缩文本文件的内容
compress or expand files
#解压 [root@localhost test2]# gzip -d linux.txt.gz [root@localhost test2]# gunzip linux.txt.gz #解压目录下文件,不会解打包 [root@localhost test2]# gunzip -r test/ #-zcat查看压缩文本文件的内容 [root@localhost test2]# zcat linux.txt.gz linux
四 .bz格式 ——命令不支持压缩目录
1. bzip2 命令——压缩文件
- .bz格式 算法更先进、压缩比更好;.gz相对压缩时间快
- 语法:bzip2 [选项] 源文件
- bzip2 :a block-sorting file compressor
- 选项:
- -k ;压缩保留源文件
- -d:解压缩
- -v:显示压缩文件信息
- -数字:用于指定压缩等级,默认-6,-1压缩比最低,-9压缩比最高
#基本压缩:压缩文件生成,源文件消失 [root@localhost test2]# bzip2 linux.txt #保留源文件压缩 [root@localhost test2]# gzip -K linux.txt > linux.txt.gz
2. bzip2 -d 和 bunzip2 命令——.bz的解压命令
语法:bzip2 -d 压缩包
语法:bunzip2 [-k] 压缩包
选项:-k:解压保留源文件
语法:bzcat 纯文本压缩包:查看压缩文本文件的内容