赞
踩
将许多零散的文件打包,并记录好各自的位置
−并不压缩其存储空间
−主要起到整理、备案的作用
将单个文件按照某种算法重新编码存放
−只针对单个文件
−主要起到降低文件大小、节省磁盘空间的作用
zip 备份操作
−用法:zip [-r] 压缩包名被压缩的文档...
先安装命令zip
- [root@hadoop ~]# yum install zip
- Setting up Install Process
- Resolving Dependencies
- --> Running transaction check
- ---> Package zip.x86_64 0:3.0-1.el6_7.1 will be installed
- --> Finished Dependency Resolution
-
- Dependencies Resolved
-
- ========================================================================================================================
- Package Arch Version Repository Size
- ========================================================================================================================
- Installing:
- zip x86_64 3.0-1.el6_7.1 base 259 k
-
- Transaction Summary
- ========================================================================================================================
- Install 1 Package(s)
-
- Total download size: 259 k
- Installed size: 804 k
- Is this ok [y/N]: y
- Downloading Packages:
- zip-3.0-1.el6_7.1.x86_64.rpm | 259 kB 00:00
- Running rpm_check_debug
- Running Transaction Test
- Transaction Test Succeeded
- Running Transaction
- Installing : zip-3.0-1.el6_7.1.x86_64 1/1
- Verifying : zip-3.0-1.el6_7.1.x86_64 1/1
-
- Installed:
- zip.x86_64 0:3.0-1.el6_7.1
-
- Complete!
- [root@hadoop ~]# ls -lh /etc >ziptest.txt //建测试文件
- [root@hadoop ~]# zip ziptest.zip ziptest.txt //压缩
- adding: ziptest.txt (deflated 79%)
- [root@hadoop ~]# ls -lh ziptest.*
- -rw-r--r--. 1 root root 8.1K Apr 29 14:38 ziptest.txt
- -rw-r--r--. 1 root root 1.9K Apr 29 14:42 ziptest.zip
任务目标
−将目录/etc/init.d和文件install.log 备份为/opt/mybak.zip
- [root@hadoop ~]# zip -r /opt/mybak.zip /etc/init.d/ install.log
- adding: etc/init.d/ (stored 0%)
- adding: etc/init.d/rsyslog (deflated 56%)
- adding: etc/init.d/rdisc (deflated 55%)
- adding: etc/init.d/ip6tables (deflated 72%)
- adding: etc/init.d/atd (deflated 62%)
- adding: etc/init.d/lvm2-monitor (deflated 52%)
- adding: etc/init.d/lvm2-lvmetad (deflated 50%)
- adding: etc/init.d/blk-availability (deflated 43%)
- adding: etc/init.d/ntpd (deflated 57%)
- adding: etc/init.d/functions (deflated 67%)
- adding: etc/init.d/sshd (deflated 66%)
- adding: etc/init.d/restorecond (deflated 54%)
- adding: etc/init.d/udev-post (deflated 56%)
- adding: etc/init.d/mysqld (deflated 63%)
- adding: etc/init.d/crond (deflated 64%)
- adding: etc/init.d/auditd (deflated 60%)
- adding: etc/init.d/iptables (deflated 71%)
- adding: etc/init.d/halt (deflated 57%)
- adding: etc/init.d/single (deflated 41%)
- adding: etc/init.d/netconsole (deflated 56%)
- adding: etc/init.d/saslauthd (deflated 57%)
- adding: etc/init.d/network (deflated 65%)
- adding: etc/init.d/sandbox (deflated 56%)
- adding: etc/init.d/netfs (deflated 67%)
- adding: etc/init.d/ntpdate (deflated 51%)
- adding: etc/init.d/postfix (deflated 62%)
- adding: etc/init.d/killall (deflated 45%)
- adding: install.log (deflated 73%)
unzip 解压操作−用法:unzip [-d 目标文件夹] .zip压缩包
安装命令
- [root@hadoop ~]# yum install unzip
- Setting up Install Process
- Resolving Dependencies
- --> Running transaction check
- ---> Package unzip.x86_64 0:6.0-5.el6 will be installed
- --> Finished Dependency Resolution
-
- Dependencies Resolved
-
- ========================================================================================================================
- Package Arch Version Repository Size
- ========================================================================================================================
- Installing:
- unzip x86_64 6.0-5.el6 base 152 k
-
- Transaction Summary
- ========================================================================================================================
- Install 1 Package(s)
-
- Total download size: 152 k
- Installed size: 324 k
- Is this ok [y/N]: y
- Downloading Packages:
- unzip-6.0-5.el6.x86_64.rpm | 152 kB 00:00
- Running rpm_check_debug
- Running Transaction Test
- Transaction Test Succeeded
- Running Transaction
- Installing : unzip-6.0-5.el6.x86_64 1/1
- Verifying : unzip-6.0-5.el6.x86_64 1/1
-
- Installed:
- unzip.x86_64 0:6.0-5.el6
-
- Complete!
- [root@hadoop ~]# unzip -d zdir/ ziptest.zip //释放到指定目录
- Archive: ziptest.zip
- inflating: zdir/ziptest.txt
- [root@hadoop ~]# ls zdir/
- ziptest.txt
- [root@hadoop ~]# cd /opt/
- [root@hadoop opt]# unzip /opt/mybak.zip //释放到当前目录
- Archive: /opt/mybak.zip
- creating: etc/init.d/
- inflating: etc/init.d/rsyslog
- inflating: etc/init.d/rdisc
- inflating: etc/init.d/ip6tables
- inflating: etc/init.d/atd
gzip压缩操作
−用法:gzip[-9] 文件名...
-分别压缩每个文件,原始文件不保留
- [root@hadoop opt]# ls -lh /etc/ >gztest.txt //建测试文件
- [root@hadoop opt]# gzip gztest.txt //压缩
- [root@hadoop opt]# ls -lh gztest.txt*
- -rw-r--r--. 1 root root 1.8K Apr 29 14:51 gztest.txt.gz
gunzip解压操作
−用法1:gunzip.gz压缩包.. ..
−用法2:gzip-d .gz压缩包.. ..
−分别解压每个.gz包文件,原始文件不保留
- [root@hadoop opt]# gzip -d gztest.txt.gz //解压缩
- [root@hadoop opt]# ls -lh gztest.txt*
- -rw-r--r--. 1 root root 8.1K Apr 29 14:51 gztest.txt
tar 制作备份
−用法:tar -cf.tar归档包名被归档的文件.. ..
−逐一复制并归档,原始文件保留
−选项含义:-c 创建、-v 细节、-P 保留根路径、-f 归档
- [root@hadoop opt]# tar -cf slbak.tar /etc/selinux //新建归档
- tar: Removing leading `/' from member names
- [root@hadoop opt]# tar -tf slbak.tar //查看归档内容
- etc/selinux/
- etc/selinux/restorecond_user.conf
- etc/selinux/config
tar 释放备份
−用法:tar -xf.tar归档包[-C 目标目录]
−解包并逐一提取,原始文件保留
−选项含义:-x 释放、-C 存放的目标位置
- [root@hadoop opt]# tar -xf slbak.tar -C /opt/ //释放归档到指定目录
- [root@hadoop opt]# ls /opt/etc/selinux/
- config restorecond.conf restorecond_user.conf semanage.conf targeted
任务目标
−将/etc和/srv目录备份为/opt/etcsrv.tar.gz 文件
−保留原始文档的根路径(-P)、权限等属性(-p)
- [root@hadoop opt]# tar -zcpPf /opt/etcsrv.tar.gz /etc/ /srv/
- [root@hadoop opt]# ls -lh /opt/etcsrv.tar.gz
- -rw-r--r--. 1 root root 8.1M Apr 29 15:02 /opt/etcsrv.tar.gz
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。