解压缩命令

压缩技术:

1.如记录数字1,二进制最右是1个bit,其他7个bits会自动填0,工程师利用复杂的计算方式,将这些空间丢出来

2.将重复的数据进行统计记录,如果你的数据有100个1时,记录为100个1

常见压缩格式:

.gz gzip程序压缩          

.bz2 bzip2程序压缩

.tar tar程序打包的数据,没有压缩过

.tar.gz tar打包后,由gzip压缩

.tar.bz2 tar打包后,由bzip2压缩

常用命令:

gzip、gunzip、bzip2、tar、zcat、bzcat

命令详解:

1.gzip命令:是GUN zip的缩写, 以.gz结尾,用于压缩文件。此命令有压缩等级,默认-6.最快是0但压缩效果差。-9压缩效果好但速度慢

语法格式:

gzip [ -acdfhlLnNrtvV19 ] [-S suffix] [ name ...  ]

常用选项:

-d  将压缩文件解压缩并删除压缩文件

-v  显示执行过程

-V 显示gzip版本信息

-f  强制压缩文件

-h  help

-r  递归处理,将目录下的文件及子目录一并处理(目录下的所有文件都压缩)

实例:

#压缩
[root@www1 yang]# gzip install.log
[root@www1 yang]# ll
总用量 4
-rw-r--r-- 1 root root 32 7月   5 07:38 install.log.gz
-rw-r--r-- 1 root root  0 5月  24 16:13 test.txt

#解压缩
[root@www1 yang]# gzip -dv install.log.gz
install.log.gz:   0.0% -- replaced with install.log
[root@www1 yang]# ll
总用量 0
-rw-r--r-- 1 root root 0 7月   5 07:38 install.log
-rw-r--r-- 1 root root 0 5月  24 16:13 test.txt

#递归压缩
[root@www1 ~]# gzip -r yang
[root@www1 ~]# ll yang*
yang:
总用量 8
-rw-r--r-- 1 root root 32 7月   5 07:38 install.log.gz
-rw-r--r-- 1 root root 29 5月  24 16:13 test.txt.gz

2.gunzip命令:用于解压缩由gzip压缩的文件

语法格式:

gunzip [ -acfhlLnNrtvV ] [-S suffix] [ name ...  ]

常用选项:

-l 显示压缩文件的详细信息

-s 递归处理

-v 显示执行过程

实例:

#查看压缩文件详细信息
[root@www1 yang]# gunzip -l install.log.gz
         compressed        uncompressed  ratio uncompressed_name
                 32                   0   0.0% install.log

#解压缩文件并显示过程                 
[root@www1 yang]# gunzip -v install.log.gz
install.log.gz:   0.0% -- replaced with install.log
[root@www1 yang]# ll
总用量 4
-rw-r--r-- 1 root root  0 7月   5 07:38 install.log
-rw-r--r-- 1 root root 29 5月  24 16:13 test.txt.gz
[root@www1 yang]# gzip install.log

#递归解压
[root@www1 ~]# gunzip -r yang
[root@www1 ~]# ll yang
总用量 0
-rw-r--r-- 1 root root 0 7月   5 07:38 install.log
-rw-r--r-- 1 root root 0 5月  24 16:13 test.txt

3.bzip2命令:

语法格式:

bzip2, bunzip2 - a block-sorting file compressor, v1.0.4,以.bz2结尾

常用选项:

-z 压缩选项

-d 解压缩选项

-k 压缩后会删除源文件,若不删除,使用此参数

实例:

#压缩
[root@www1 yang]# bzip2 install.log
[root@www1 yang]# ll
总用量 4
-rw-r--r-- 1 root root 14 7月   5 07:38 install.log.bz2
-rw-r--r-- 1 root root  0 5月  24 16:13 test.txt

#解压缩
[root@www1 yang]# bzip2 -dv install.log.bz2
  install.log.bz2: done
[root@www1 yang]# ll
总用量 0
-rw-r--r-- 1 root root 0 7月   5 07:38 install.log
-rw-r--r-- 1 root root 0 5月  24 16:13 test.txt

#压缩并保留源文件
[root@www1 yang]# bzip2 -kv install.log
  install.log:  no data compressed.
[root@www1 yang]# ll
总用量 4
-rw-r--r-- 1 root root  0 7月   5 07:38 install.log
-rw-r--r-- 1 root root 14 7月   5 07:38 install.log.bz2
-rw-r--r-- 1 root root  0 5月  24 16:13 test.txt

4.zcat、bzcat在不解压缩文件的同时可以查看压缩文件内容,都是将压缩文件输出到标准输出流中。

语法格式:

zcat [ -fhLV ] [ name ...  ]

bzcat [ -s ] [ filenames ...  ]

实例:

[root@www1 yang]# ll
总用量 8
-rw-r--r-- 1 root root  67 7月   5 08:35 install.log.bz2
-rw-r--r-- 1 root root 325 7月   5 08:36 test.txt
[root@www1 yang]# >test.txt
[root@www1 yang]# bzcat install.log.bz2 >test.txt
[root@www1 yang]# cat test.txt
九 july
九 july
九 july
九 july
九 july
九 july
九 july
九 july
[root@www1 yang]# bzip2 -d install.log.bz2
[root@www1 yang]# ll
总用量 8
-rw-r--r-- 1 root root 325 7月   5 08:35 install.log
-rw-r--r-- 1 root root 325 7月   5 08:40 test.txt
[root@www1 yang]# gzip install.log
[root@www1 yang]# zcat install.log.gz >>test.txt
You have mail in /var/spool/mail/root
[root@www1 yang]# cat test.txt
九 july
九 july
九 july
九 july
九 july
九 july

5.tar命令   

语法格式:

tar [OPTION...] [FILE]...

常用选项:

-c create 创建打包文件

-x extract 解包

-f 指定包名

-v 列出执行过程

-t 查看包中的文件

-z 具有gzip格式的

-j 具有bzip2格式的

实例:

#打包
[root@www1 yang]# tar -c -f bao.tar install.log test.txt
[root@www1 yang]# ll
-rw-r--r-- 1 root root 10240 7月   5 11:07 bao.tar

#解包指定路径
[root@www1 yang]# tar -x -f bao.tar -C test
[root@www1 yang]# ll test
总用量 8
-rw-r--r-- 1 root root 325 7月   5 08:35 install.log
-rw-r--r-- 1 root root 650 7月   5 08:41 test.txt

#打包并压缩为.gz
[root@www1 yang]# tar -zcvf bao.tar.gz install.log test.txt
install.log
test.txt
[root@www1 yang]# ll bao.tar.gz
-rw-r--r-- 1 root root 181 7月   5 11:20 bao.tar.gz
[root@www1 yang]#

#打包并压缩为.bz2
[root@www1 yang]# tar -jcvf bao.tar.bz2 install.log test.txt
install.log
test.txt
[root@www1 yang]# ll bao.tar.bz2
-rw-r--r-- 1 root root 200 7月   5 11:21 bao.tar.bz2
[root@www1 yang]#

#解压缩包
[root@www1 yang]# tar -zxvf bao.tar.gz -C test1
install.log
test.txt
[root@www1 yang]# tar -jxvf bao.tar.bz2 -C test2
install.log
test.txt
[root@www1 yang]# ll test1 test2
test1:
总用量 8
-rw-r--r-- 1 root root 325 7月   5 08:35 install.log
-rw-r--r-- 1 root root 650 7月   5 08:41 test.txt

test2:
总用量 8
-rw-r--r-- 1 root root 325 7月   5 08:35 install.log
-rw-r--r-- 1 root root 650 7月   5 08:41 test.txt
[root@www1 yang]#



猜你喜欢

转载自blog.51cto.com/12107790/2139948