gzip,zcat/zmore/zless/zgrep
c 将压缩的数据输出到屏幕上,可以透过数据流重导来处理,不删除源文件
-d 解压.gz文件
-v 打印操作详细信息
-l 列出压缩文件详细信息,可以显示压缩比
-# 延时等级,默认为6 -1最快,压缩比低 -9最慢,压缩比高
-h 在线帮助
压缩文件
# ls -lh
total 656K
-rw-r--r--. 1 root root 655K Jun 7 2013 services
# gzip -v services
services: 79.7% -- replaced with services.gz
# ls -lh
total 136K
-rw-r--r--. 1 root root 133K Jun 7 2013 services.gz
解压缩文件
# gzip -d services.gz
# ll
total 656
-rw-r--r--. 1 root root 670293 Jun 7 2013 services
压缩不删除源文件
# gzip -9 -c services > services.gz
# ll
total 792
-rw-r--r--. 1 root root 670293 Jun 7 2013 services
-rw-r--r--. 1 root root 135489 Mar 22 11:43 services.gz
列出压缩文件详细信息,可以显示压缩比
# gzip -l services.gz
compressed uncompressed ratio uncompressed_name
135489 670293 79.8% services
打印源文件
# zcat services.gz
正则表达式查看services源文件
# zgrep -n "http" services.gz
14:# http://www.iana.org/assignments/port-numbers
89:http 80/tcp www www-http # WorldWideWeb HTTP
90:http 80/udp www www-http # HyperText Transfer Protocol
91:http 80/sctp # HyperText Transfer Protocol
197:https 443/tcp # http protocol over TLS/SSL
bzip2,bzcat/bzmore/bzless/bzgrep
c 将压缩的数据输出到屏幕上,可以透过数据流重导来处理,不删除源文件
-d 解压.gz文件
-k 保留源文件,而不会删除原始文件
-z 压缩参数(默认值,可以不加)
-v 打印操作详细信息
-# 延时等级,默认为6 -1最快,压缩比低 -9最慢,压缩比高
-h 在线帮助
# yum -y install bzip2
压缩文件
# bzip2 -v services
services: 5.409:1, 1.479 bits/byte, 81.51% saved, 670293 in, 123932 out.
读取文件内容
# bzcat services.bz2 | less
# /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
解压缩文件:
# bzip2 -d services.bz2
压缩不删除源文件
# bzip2 -9 -v -c services > services.bz2
services: 5.409:1, 1.479 bits/byte, 81.51% saved, 670293 in, 123932 out.
xz,xzcat/xzmore/xzless/xzgrep
c 将压缩的数据输出到屏幕上,可以透过数据流重导来处理,不删除源文件
-d 解压.gz文件
-v 打印操作详细信息
-l 列出压缩文件详细信息,可以显示压缩比
-# 延时等级,默认为6 -1最快,压缩比低 -9最慢,压缩比高
-h 在线帮助
压缩文件
# xz -v services
services (1/1)
100 % 97.3 KiB / 654.6 KiB = 0.149
# ls -lh services*
-rw-r--r--. 1 root root 122K Mar 22 12:01 services.bz2
-rw-r--r--. 1 root root 133K Mar 22 11:43 services.gz
-rw-r--r--. 1 root root 98K Jun 7 2013 services.xz
列出文件压缩信息
# xz -l services.xz
Strms Blocks Compressed Uncompressed Ratio Check Filename
1 1 97.3 KiB 654.6 KiB 0.149 CRC64 services.xz
解压文件:
# xz -d services.xz
压缩不删除源文件
# xz -9 -v -c services > services.xz
services (1/1)
100 % 97.3 KiB / 654.6 KiB = 0.149
tar:
tar [-z|-j|-J] [cv] [-f 带建立的文档名称] filename...
解压缩
tar [-z|-j|-J] [xv] [-f 带建立的文档名称] filename...
查看
tar [-z|-j|-J] [tv] [-f 带建立的文档名称] filename...
-C 目的解压缩目录
备份/etc目录保留文件权限(不会包含根目录时相对路径)
# time tar -zpcv -f /root/etc.tar.gz /etc
备份/etc目录保留文件权限(含根目录时相对路径)
# time tar -jcvpP -f /root/etc.tar.bz2 /etc
已经完成备份
# ll -lh
total 9.8M
-rw-------. 1 root root 1.6K Jun 17 2019 anaconda-ks.cfg
-rw-r--r--. 1 root root 9.8M Mar 22 12:18 etc.tar.gz
查看备份文件
# tar -tvzf etc.tar.gz
etc目录有31m
# du -sm /etc/
31 /etc/
解压备份文件:
# tar -jxf etc.tar.bz2 -C /tmp/
备份不包括文件
# tar -jcv -f /root/system.tar.bz2 --exclude=/root/etc.tar.bz2 --exclude=/root/etc.tar.gz /etc /root
备份比paswd更新的文件
# find /etc/ -newer /etc/passwd
/etc/
/etc/resolv.conf
/etc/group-
/etc/gshadow-
/etc/group
/etc/gshadow
/etc/shadow
# ll /etc/passwd
-rw-r--r--. 1 root root 999 Feb 8 22:59 /etc/passwd
# tar -jcvf /root/etcnewerthanpasswd.tar.bz2 --newer-mtime="2020/2/8" /etc/*
# ll /etc/passwd
-rw-r--r--. 1 root root 999 Feb 8 22:59 /etc/passwd