6.1 压缩打包介绍
Windows系统里常见的压缩文件格式有:rar、zip、7z等
linux系统压缩文件类型有:zip、gz、bz2、xz、tar.gz、tar.bz2、tar.xz等
文件压缩能够节省磁盘空间,更重要的是能够节省文件传输占用的网络带宽,由于企业网络带宽极其昂贵,对于企业来说能够节省其运营成本。
6.2 gzip压缩工具
gzip命令:不能压缩目录,压缩完后,原文件会删除。
[root@lgs-01 ~]# du -sh abc
3.0M abc
[root@lgs-01 ~]# gzip /root/abc
[root@lgs-01 ~]# ls -l abc.gz
-rwxr-xr-x. 1 root root 1090830 4月 16 18:00 abc.gz
[root@lgs-01 ~]# du -sh abc.gz
1.1M abc.gz
[root@lgs-01 ~]# ls -l abc
ls: 无法访问abc: 没有那个文件或目录
可以指定压缩级别:-(1-9),默认的压缩级别是6,级别越高消耗越大的cpu资源。
[root@lgs-01 ~]# gzip -9 abc
[root@lgs-01 ~]# du -sh abc.gz
1.1M abc.gz
解压缩:gzip -d或者 gunzip命令,解压缩后原来的压缩文件会删除。
[root@lgs-01 ~]# gzip -d abc.gz
[root@lgs-01 ~]# du -sh abc
3.0M abc
查看压缩文件内容:ccat,先解压,在cat查看内容
[root@lgs-01 ~]# gzip xxx.conf
[root@lgs-01 ~]# zcat xxx.conf.gz
#
#
# This file is used by the man-db package to configure the man and cat paths.
# It is also used to provide a manpath for those without one by examining
# their PATH environment variable. For details see the manpath(5) man page.
#
# Lines beginning with `#' are comments and are ignored. Any combination of
# tabs or spaces may be used as `whitespace' separators.
#
# There are three mappings allowed in this file:
# --------------------------------------------------------
# MANDATORY_MANPATH manpath_element
# MANPATH_MAP path_element manpath_element
# MANDB_MAP global_manpath [relative_catpath]
gzip -c:指定压缩文件保存目录,原文件不删除。
[root@lgs-01 ~]# gzip -c zb.txt > /root/c/666.gz
[root@lgs-01 ~]# ls -l zb.txt
-rw-r--r--. 1 root root 4350 1月 24 2017 zb.txt
[root@lgs-01 ~]# ls -l c/666.gz
-rw-r--r--. 1 root root 1656 4月 16 18:15 c/666.gz
6.3 bzip2压缩工具
bzip2命令:压缩成bz2文件,不能压缩目录,压缩算法与gzip不同,压缩率更高
[root@lgs-01 ~]# bzip2 abc
[root@lgs-01 ~]# du -sh abc.bz2
1.1M abc.bz2
解压命令:bzip2 -d 或者 bunzip2
[root@lgs-01 ~]# bzip2 -d abc.bz2
[root@lgs-01 ~]# du -sh abc
3.0M abc
指定压缩文件保存的目录:bzip2 -c
[root@lgs-01 ~]# bzip2 -c abc > c/abc1.bz2
[root@lgs-01 ~]# ls -l c/abc1.bz2
-rw-r--r--. 1 root root 1078029 4月 16 18:27 c/abc1.bz2
查看压缩文件内容:bzcat
[root@lgs-01 ~]# bzip2 xxx.conf
[root@lgs-01 ~]# bzcat xxx.conf.bz2
#
#
# This file is used by the man-db package to configure the man and cat paths.
# It is also used to provide a manpath for those without one by examining
# their PATH environment variable. For details see the manpath(5) man page.
#
# Lines beginning with `#' are comments and are ignored. Any combination of
# tabs or spaces may be used as `whitespace' separators.
#
# There are three mappings allowed in this file:
# --------------------------------------------------------
# MANDATORY_MANPATH manpath_element
# MANPATH_MAP path_element manpath_element
# MANDB_MAP global_manpath [relative_catpath]
可以指定压缩级别:-(1-9),默认的压缩级别是6,级别越高消耗越大的cpu资源。
[root@lgs-01 ~]# bzip2 -1 xxx.conf
[root@lgs-01 ~]# du -sh xxx.conf.bz2
4.0K xxx.conf.bz2
6.4 xz压缩工具
压缩命令:xz 。不支持压缩目录,压缩率比gzip和bzip2更高
[root@lgs-01 ~]# xz abc
[root@lgs-01 ~]# du -sh abc.xz
816K abc.xz
解压命令:xz -d或者unxz
[root@lgs-01 ~]# unxz abc.xz
[root@lgs-01 ~]# ls -l abc
-rwxr-xr-x. 1 root root 3073568 4月 16 18:00 abc
指定压缩文件存放的目录:-c
[root@lgs-01 ~]# xz -c abc > c/abc1.xz
[root@lgs-01 ~]# ls -l c/abc1.xz
-rw-r--r--. 1 root root 831676 4月 16 18:35 c/abc1.xz
压缩级别: -(1-9),默认为6
[root@lgs-01 ~]# xz -9 abc
[root@lgs-01 ~]# du -sh abc.xz
816K abc.xz
查看压缩文件内容:xzcat
[root@lgs-01 ~]# xz xxx.conf
[root@lgs-01 ~]# xzcat xxx.conf.xz
#
#
# This file is used by the man-db package to configure the man and cat paths.
# It is also used to provide a manpath for those without one by examining
# their PATH environment variable. For details see the manpath(5) man page.
#
# Lines beginning with `#' are comments and are ignored. Any combination of
# tabs or spaces may be used as `whitespace' separators.
#
# There are three mappings allowed in this file:
# --------------------------------------------------------
# MANDATORY_MANPATH manpath_element
# MANPATH_MAP path_element manpath_element
# MANDB_MAP global_manpath [relative_catpath]