(十三)压缩
常见压缩档案的附档名:
- *.Z compress程序压缩的档案
- *.bz2 bzaip2程序压缩的档案
- *.gz gzip程序压缩的档案
- *.tar tar程序打包的数据,并没有压缩过
- *.tar.gz tar程序打包的数据,其中并且经过gzip的压缩
compress
格式:compress [-dcr] 档案或目录
参数:
-d:用来解压缩的参数
-r:可以连同目录下的档案也同事给予压缩
-c:将压缩数据输出到屏幕
gzip,zcat
压缩格式:gzip [-cdt#] 档案名
将压缩档案读出来显示在屏幕上格式:zcat 档案名.gz
参数:
-c:将压缩的数据输出到屏幕上
-d:解压的参数
-t:可以用来检验一个压缩档的一致性,看看档案有无错误
-#:压缩等级,-1最快(压缩比最差),-9最慢(压缩比最好),预设是-6
范例一:将/etc/man.config以gzip压缩
1 [root@localhost ~]# cd /tmp //进入到tmp目录 2 [root@localhost tmp]# ls -l //查看tmp目录下所有的文件 3 总用量 8 4 srwxrwxrwx. 1 root root 0 8月 12 18:28 fcoemon.dcbd.1383 5 srwxrwxrwx. 1 root root 0 10月 9 17:25 fcoemon.dcbd.1499 6 srwxrwxrwx. 1 root root 0 9月 2 00:59 fcoemon.dcbd.1504 7 srwxrwxrwx. 1 root root 0 10月 12 17:36 fcoemon.dcbd.1510 8 srwxrwxrwx. 1 root root 0 10月 12 18:30 fcoemon.dcbd.1514 9 srwxrwxrwx. 1 root root 0 8月 28 00:32 fcoemon.dcbd.1522 10 srwxrwxrwx. 1 root root 0 10月 13 17:15 fcoemon.dcbd.1524 11 -rw-r--r--. 1 root root 4940 10月 12 18:41 man.config 12 [root@localhost tmp]# gzip man.config //将man.config压缩 13 [root@localhost tmp]# ls -l 14 总用量 4 15 srwxrwxrwx. 1 root root 0 8月 12 18:28 fcoemon.dcbd.1383 16 srwxrwxrwx. 1 root root 0 10月 9 17:25 fcoemon.dcbd.1499 17 srwxrwxrwx. 1 root root 0 9月 2 00:59 fcoemon.dcbd.1504 18 srwxrwxrwx. 1 root root 0 10月 12 17:36 fcoemon.dcbd.1510 19 srwxrwxrwx. 1 root root 0 10月 12 18:30 fcoemon.dcbd.1514 20 srwxrwxrwx. 1 root root 0 8月 28 00:32 fcoemon.dcbd.1522 21 srwxrwxrwx. 1 root root 0 10月 13 17:15 fcoemon.dcbd.1524 22 -rw-r--r--. 1 root root 2184 10月 12 18:41 man.config.gz 23 [root@localhost tmp]#
范例二:将man.config.gz内容读出来
1 [root@localhost tmp]# zcat man.config.gz 2 # 3 # Generated automatically from man.conf.in by the 4 # configure script. 5 # 6 # man.conf from man-1.6f 7 # 8 ......
范例三:将man.config.gz解压缩
1 [root@localhost tmp]# gzip -d man.config.gz 2 [root@localhost tmp]# ls -l 3 总用量 8 4 srwxrwxrwx. 1 root root 0 8月 12 18:28 fcoemon.dcbd.1383 5 srwxrwxrwx. 1 root root 0 10月 9 17:25 fcoemon.dcbd.1499 6 srwxrwxrwx. 1 root root 0 9月 2 00:59 fcoemon.dcbd.1504 7 srwxrwxrwx. 1 root root 0 10月 12 17:36 fcoemon.dcbd.1510 8 srwxrwxrwx. 1 root root 0 10月 12 18:30 fcoemon.dcbd.1514 9 srwxrwxrwx. 1 root root 0 8月 28 00:32 fcoemon.dcbd.1522 10 srwxrwxrwx. 1 root root 0 10月 13 17:15 fcoemon.dcbd.1524 11 -rw-r--r--. 1 root root 4940 10月 12 18:41 man.config
范例四:将man.config用最佳的压缩比例压缩,并保留原本的档案
1 [root@localhost tmp]# gzip -9 -c man.config >man.config.gz 2 [root@localhost tmp]# ls -l 3 总用量 8 4 srwxrwxrwx. 1 root root 0 8月 12 18:28 fcoemon.dcbd.1383 5 srwxrwxrwx. 1 root root 0 10月 9 17:25 fcoemon.dcbd.1499 6 srwxrwxrwx. 1 root root 0 9月 2 00:59 fcoemon.dcbd.1504 7 srwxrwxrwx. 1 root root 0 10月 12 17:36 fcoemon.dcbd.1510 8 srwxrwxrwx. 1 root root 0 10月 12 18:30 fcoemon.dcbd.1514 9 srwxrwxrwx. 1 root root 0 8月 28 00:32 fcoemon.dcbd.1522 10 srwxrwxrwx. 1 root root 0 10月 13 17:15 fcoemon.dcbd.1524 11 -rw-r--r--. 1 root root 31 10月 13 18:20 man.config 12 -rw-r--r--. 1 root root 55 10月 13 18:20 man.config.gz
bzip,bzcat
格式:bzip2 [-cdz] 档名
读取压缩文件的内容:bzcat 档名.bz2
参数:
-c:将压缩的过程产生输出到屏幕上
-d:解压的参数
-z:压缩的参数
-#:-9最佳,-1最快
范例:将/tmp/man.comfig以bzip2压缩
1 [root@localhost tmp]# bzip2 man.config 2 [root@localhost tmp]# ls -l 3 总用量 4 4 srwxrwxrwx. 1 root root 0 8月 12 18:28 fcoemon.dcbd.1383 5 srwxrwxrwx. 1 root root 0 10月 9 17:25 fcoemon.dcbd.1499 6 srwxrwxrwx. 1 root root 0 9月 2 00:59 fcoemon.dcbd.1504 7 srwxrwxrwx. 1 root root 0 10月 12 17:36 fcoemon.dcbd.1510 8 srwxrwxrwx. 1 root root 0 10月 12 18:30 fcoemon.dcbd.1514 9 srwxrwxrwx. 1 root root 0 8月 28 00:32 fcoemon.dcbd.1522 10 srwxrwxrwx. 1 root root 0 10月 13 17:15 fcoemon.dcbd.1524 11 -rw-r--r--. 1 root root 74 10月 13 18:20 man.config.bz2
范例二:将man.config.bz2解压缩
1 [root@localhost tmp]# bzip2 -d man.config.bz2 2 [root@localhost tmp]# ls -l 3 总用量 4 4 srwxrwxrwx. 1 root root 0 8月 12 18:28 fcoemon.dcbd.1383 5 srwxrwxrwx. 1 root root 0 10月 9 17:25 fcoemon.dcbd.1499 6 srwxrwxrwx. 1 root root 0 9月 2 00:59 fcoemon.dcbd.1504 7 srwxrwxrwx. 1 root root 0 10月 12 17:36 fcoemon.dcbd.1510 8 srwxrwxrwx. 1 root root 0 10月 12 18:30 fcoemon.dcbd.1514 9 srwxrwxrwx. 1 root root 0 8月 28 00:32 fcoemon.dcbd.1522 10 srwxrwxrwx. 1 root root 0 10月 13 17:15 fcoemon.dcbd.1524 11 -rw-r--r--. 1 root root 31 10月 13 18:20 man.config
范例三:将man.config用最佳的比例压缩,并保留原本的档案
1 [root@localhost tmp]# bzip2 -9 -c man.config >man.config.bz2 2 [root@localhost tmp]# ls -l 3 总用量 8 4 srwxrwxrwx. 1 root root 0 8月 12 18:28 fcoemon.dcbd.1383 5 srwxrwxrwx. 1 root root 0 10月 9 17:25 fcoemon.dcbd.1499 6 srwxrwxrwx. 1 root root 0 9月 2 00:59 fcoemon.dcbd.1504 7 srwxrwxrwx. 1 root root 0 10月 12 17:36 fcoemon.dcbd.1510 8 srwxrwxrwx. 1 root root 0 10月 12 18:30 fcoemon.dcbd.1514 9 srwxrwxrwx. 1 root root 0 8月 28 00:32 fcoemon.dcbd.1522 10 srwxrwxrwx. 1 root root 0 10月 13 17:15 fcoemon.dcbd.1524 11 -rw-r--r--. 1 root root 31 10月 13 18:20 man.config 12 -rw-r--r--. 1 root root 74 10月 13 18:59 man.config.bz2
tar
格式:tar [-cxtzjvfp] 档案或目录
参数:
-c:建立一个压缩档案的参数指令
-x:解开一个压缩文档的参数指令
-t:查看tarfile里面的档案(在参数的下达中,c/x/t只能存在一个,因为不可能同时压缩与解压缩)
-z:是否具有gzip的属性,是否需要用gzip压缩
-j:是否具有bzip2的属性,是否需要用bzip2压缩
-v:压缩的过程中显示档案名
-f:使用档名(f必须为最后一个参数)
-p:使用原档案的原来属性
# tar -cf all.tar *.jpg
这条命令是将所有.jpg的文件打成一个名为all.tar的包。-c是表示产生新的包,-f指定包的文件名。
# tar -rf all.tar *.gif
这条命令是将所有.gif的文件增加到all.tar的包里面去。-r是表示增加文件的意思。
# tar -uf all.tar logo.gif
这条命令是更新原来tar包all.tar中logo.gif文件,-u是表示更新文件的意思。
# tar -tf all.tar
这条命令是列出all.tar包中所有文件,-t是列出文件的意思
# tar -xf all.tar
这条命令是解出all.tar包中所有文件,-x是解开的意思
压缩
- tar –cvf jpg.tar *.jpg 将目录里所有jpg文件打包成tar.jpg
- tar –czf jpg.tar.gz *.jpg 将目录里所有jpg文件打包成jpg.tar后,并且将其用gzip压缩,生成一个gzip压缩过的包,命名为jpg.tar.gz
- tar –cjf jpg.tar.bz2 *.jpg 将目录里所有jpg文件打包成jpg.tar后,并且将其用bzip2压缩,生成一个bzip2压缩过的包,命名为jpg.tar.bz2
- tar –cZf jpg.tar.Z *.jpg 将目录里所有jpg文件打包成jpg.tar后,并且将其用compress压缩,生成一个umcompress压缩过的包,命名为jpg.tar.Z
- rar a jpg.rar *.jpg rar格式的压缩,需要先下载rar for linux
- zip jpg.zip *.jpg zip格式的压缩,需要先下载zip for linux
解压
- tar –xvf file.tar 解压 tar包
- tar -xzvf file.tar.gz 解压tar.gz
- tar -xjvf file.tar.bz2 解压 tar.bz2
- tar –xZvf file.tar.Z 解压tar.Z
- unrar e file.rar 解压rar
- unzip file.zip 解压zip


浙公网安备 33010602011771号