Linux_centos7_文件与文件系统的压缩/打包与备份_(5)_(bird_bro)

本文介绍了Linux CentOS7系统中如何进行文件和文件系统的压缩、打包以及备份操作,重点关注文件压缩这一环节。
摘要由CSDN通过智能技术生成
文件与文件系统压缩、打包与备份

tar/gz/bz/xz/dd

文件压缩


#按照文件大小检视文件,默认文件由大到小排序,参数 -r 可指定从小到大排序
[kingarthur@localhost ~]$ ls -ldSr /etc/*
-rw-r--r--.  1 root root         0 Jun 10  2014 /etc/wvdial.conf
-rw-r--r--.  1 root root         0 Oct 31  2018 /etc/subuid
-rw-r--r--.  1 root root         0 Oct 31  2018 /etc/subgid
-rw-r--r--.  1 root root         0 Jun  7  2013 /etc/motd
-rw-r--r--.  1 root root         0 Jun  7  2013 /etc/exports
-rw-r--r--.  1 root root         0 Oct 31  2018 /etc/environment
-rw-------.  1 root root         0 Mar 18 07:52 /etc/crypttab
-rw-------.  1 root root         0 Apr 11  2018 /etc/cron.deny
-rw-r--r--.  1 root root         1 Mar 19 16:30 /etc/resolv.conf.save
-rw-r--r--.  1 root root         1 Oct 31  2018 /etc/at.deny
drwxr-xr-x.  2 root root         6 Apr 11  2018 /etc/xinetd.d
drwxr-xr-x.  2 root root         6 Oct 31  2018 /etc/tmpfiles.d
...
-rw-r--r--.  1 root root     26832 Oct 31  2018 /etc/dnsmasq.conf
-rw-r--r--.  1 root root     51787 May 15  2013 /etc/mime.types
-rw-r--r--.  1 root root    121699 Mar 18 08:22 /etc/ld.so.cache
-rw-r--r--.  1 root root    670293 Jun  7  2013 /etc/services
[kingarthur@localhost ~]$ ls -ldS /etc/*
-rw-r--r--.  1 root root    670293 Jun  7  2013 /etc/services
-rw-r--r--.  1 root root    121699 Mar 18 08:22 /etc/ld.so.cache
-rw-r--r--.  1 root root     12589 Jul 23  2018 /etc/slp.conf
-rw-r--r--.  1 root root     12288 Mar 18 14:27 /etc/aliases.db
drwxr-xr-x.  2 root root     12288 Mar 18 08:07 /etc/brltty
...
-rw-r--r--.  1 root root         0 Jun  7  2013 /etc/motd
-rw-r--r--.  1 root root         0 Oct 31  2018 /etc/subgid
-rw-r--r--.  1 root root         0 Oct 31  2018 /etc/subuid
-rw-r--r--.  1 root root         0 Jun 10  2014 /etc/wvdial.conf
[kingarthur@localhost ~]$ cd /tmp/
[kingarthur@localhost tmp]$ cp /etc/services .
[kingarthur@localhost tmp]$ ls -l ./services 
-rw-r--r--. 1 kingarthur kingarthur 670293 Apr 11 19:58 ./services
#参数 -v 显示文件压缩比
[kingarthur@localhost tmp]$ gzip -v services 
services:	 79.7% -- replaced with services.gz
#查看压缩前后文件属性
[kingarthur@localhost tmp]$ ll /etc/services /tmp/services*
-rw-r--r--. 1 root       root       670293 Jun  7  2013 /etc/services
-rw-r--r--. 1 kingarthur kingarthur 136088 Apr 11 19:58 /tmp/services.gz
#源文件为文本文件,指令 zcat 读取压缩文件内容
[kingarthur@localhost tmp]$ zcat services.gz 
#/etc/services:
$Id: services,v 1.55 2013/04/14 ovasik Exp $
#
#Network services, Internet style
#IANA services version: last updated 2013-04-10
#
#Note that it is presently the policy of IANA to assign a single well-known
#port number for both TCP and UDP; hence, most entries here have two entries
#even if the protocol doesn't support UDP operations.
#Updated from RFC 1700, ``Assigned Numbers'' (October 1994).  Not all ports
#are included, only the more common ones.
#
#The latest IANA port assignments can be gotten from
#http://www.iana.org/assignments/port-numbers
#The Well Known Ports are those from 0 through 1023.
#The Registered Ports are those from 1024 through 49151
#The Dynamic and/or Private Ports are those from 49152 through 65535
#
#Each line describes one service, and is of the form:
#
#service-name  port/protocol  [aliases ...]   [# comment]

tcpmux          1/tcp                           # TCP port service multiplexer
tcpmux          1/udp                           # TCP port service multiplexer
rje             5/tcp                           # Remote Job Entry
rje             5/udp                           # Remote Job Entry
echo            7/tcp
echo            7/udp
...

#文件解压缩 参数 -d 
[kingarthur@localhost tmp]$ gzip -d services.gz 
[kingarthur@localhost tmp]$ ls -l service*
-rw-r--r--. 1 kingarthur kingarthur 670293 Apr 11 19:58 services
#参数 -n 指定压缩等级,最高等级为9,参数 -c 将压缩文件内容输出到屏幕
#符号 > 将压缩后文件存入新文件,源文件被保留
[kingarthur@localhost tmp]$ gzip -9 -c services > services.gz
[kingarthur@localhost tmp]$ ls -l service*
-rw-r--r--. 1 kingarthur kingarthur 670293 Apr 11 19:58 services
-rw-rw-r--. 1 kingarthur kingarthur 135489 Apr 11 20:16 services.gz
#输出压缩文件中包含 'http' 关键字的行及其行号
[kingarthur@localhost tmp]$ zgrep -n 'http' services.gz 
14:#       http://www.iana.org/a
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值