6.1 tar:打包备份
tar命令
tar命令选项
备份站点目录html
[root@cs6 ~]# mkdir -p /var/www/html/oldboy/test
[root@cs6 ~]# touch /var/www/html/{1..10}.html
[root@cs6 ~]# ls /var/www/html/
10.html 1.html 2.html 3.html 4.html 5.html 6.html 7.html 8.html 9.html oldboy
[root@cs6 ~]# cd /var/www/
[root@cs6 www]# ls
html
[root@cs6 www]# tar zcvf www.tar.gz ./html
./html/
./html/4.html
./html/7.html
./html/oldboy/
./html/oldboy/test/
./html/9.html
./html/2.html
./html/5.html
./html/3.html
./html/6.html
./html/10.html
./html/1.html
./html/8.html
[root@cs6 www]# ll -h www.tar.gz
-rw-r--r--. 1 root root 255 May 12 18:20 www.tar.gz[root@cs6 www]# tar ztvf www.tar.gz #<一使用选项-t不解压就可以查看压缩包的内容,选项v可以显示文件的属性。
drwxr-xr-x root/root 0 2019-05-12 18:19 ./html/
-rw-r--r-- root/root 0 2019-05-12 18:19 ./html/4.html
-rw-r--r-- root/root 0 2019-05-12 18:19 ./html/7.html
drwxr-xr-x root/root 0 2019-05-12 18:19 ./html/oldboy/
drwxr-xr-x root/root 0 2019-05-12 18:19 ./html/oldboy/test/
-rw-r--r-- root/root 0 2019-05-12 18:19 ./html/9.html
-rw-r--r-- root/root 0 2019-05-12 18:19 ./html/2.html
-rw-r--r-- root/root 0 2019-05-12 18:19 ./html/5.html
-rw-r--r-- root/root 0 2019-05-12 18:19 ./html/3.html
-rw-r--r-- root/root 0 2019-05-12 18:19 ./html/6.html
-rw-r--r-- root/root 0 2019-05-12 18:19 ./html/10.html
-rw-r--r-- root/root 0 2019-05-12 18:19 ./html/1.html
-rw-r--r-- root/root 0 2019-05-12 18:19 ./html/8.html[root@cs6 www]# tar ztf www.tar.gz #<==省略v选项。
./html/
./html/4.html
./html/7.html
./html/oldboy/
./html/oldboy/test/
./html/9.html
./html/2.html
./html/5.html
./html/3.html
./html/6.html
./html/10.html
./html/1.html
./html/8.html
[root@cs6 www]# tar tf www.tar.gz #<=如果不指定z选项,那么tar命令也会自动判断压缩包的类型,自动调用gzip命令。
./html/
./html/4.html
./html/7.html
./html/oldboy/
./html/oldboy/test/
./html/9.html
./html/2.html
./html/5.html
./html/3.html
./html/6.html
./html/10.html
./html/1.html
./html/8.html
解开压缩包
[root@cs6 www]# tar zxvf www.tar.gz -C /tmp/
./html/
./html/4.html
./html/7.html
./html/oldboy/
./html/oldboy/test/
./html/9.html
./html/2.html
./html/5.html
./html/3.html
./html/6.html
./html/10.html
./html/1.html
./html/8.html
[root@cs6 www]# ls /tmp/html/
10.html 1.html 2.html 3.html 4.html 5.html 6.html 7.html 8.html 9.html oldboy
[root@cs6 www]# tar xf www.tar.gz -C /tmp/ #去掉v选项也可以,只要涉及解压的操作,tar命令都能自动识别压缩包的质缩类型,但是压缩时必须要加上z选项。
排除打包
[root@cs6 www]# tar zcvf www.tar.gz ./html/ --exclude=html/oldboy/test
./html/ #<==test目录结尾不要加/,否则不会成功。
./html/4.html
./html/7.html
./html/oldboy/
./html/9.html
./html/2.html
./html/5.html
./html/3.html
./html/6.html
./html/10.html
./html/1.html
./html/8.html
[root@cs6 www]# tar zcvf www.tar.gz ./html/ --exclude=html/oldboy/test --exclude=html/oldboy
./html/ #<-=排除2个以上目录的方法:并列使用多个--exclude。
./html/4.html
./html/7.html
./html/9.html
./html/2.html
./html/5.html
./html/3.html
./html/6.html
./html/10.html
./html/1.html
./html/8.html
排除多个文件打包参数-X
[root@cs6 www]# cat list.txt
10.html
8.html
1.html
7.html
5.html
[root@cs6 www]# tar zcvfX paichu.tar.gz list.txt ./html/
./html/
./html/4.html
./html/oldboy/
./html/oldboy/test/
./html/9.html
./html/2.html
./html/3.html
./html/6.html
打包链接文件
[root@cs6 www]# cd /etc/
[root@cs6 etc]# tar zcf local.tar.gz ./rc.local
[root@cs6 etc]# tar tvf local.tar.gz
lrwxrwxrwx root/root 0 2019-05-05 23:11 ./rc.local -> rc.d/rc.local
[root@cs6 etc]# tar zcfh local_h.tar.gz ./rc.local
[root@cs6 etc]# tar tvf local_h.tar.gz
-rwxr-xr-x root/root 220 2018-06-20 00:12 ./rc.local
解决tar使用-exclude 选项时遇到的问题。
[root@cs6 www]# tar zcvf www.tar.gz ./html/ --exclude=/var/www/html/oldboy/test
./html/ #<==打包路径为相对路径,--exclude的路径为绝对路径。
./html/4.html
./html/7.html
./html/oldboy/
./html/oldboy/test/ #<==没有成功排除。
./html/9.html
./html/2.html
./html/5.html
./html/3.html
./html/6.html
./html/10.html
./html/1.html
./html/8.html
[root@cs6 www]# tar zcvf www.tar.gz ./html/ --exclude=html/oldboy/test
./html/ #<==打包路径为相对路径,--exclude的路径为相对路径。
./html/4.html
./html/7.html
./html/oldboy/
./html/9.html
./html/2.html
./html/5.html
./html/3.html
./html/6.html
./html/10.html
./html/1.html
./html/8.html[root@cs6 www]# tar zcvf www.tar.gz ./html/ --exclude=oldboy/test
./html/ #<==--exclude的相对路径去掉html也可以。
./html/4.html
./html/7.html
./html/oldboy/
./html/9.html
./html/2.html
./html/5.html
./html/3.html
./html/6.html
./html/10.html
./html/1.html
./html/8.html[root@cs6 www]# tar zcvf www.tar.gz /var/www/html/ --exclude=/var/www/html/oldboy/test
tar: Removing leading `/' from member names #<==打包路径为绝对路径,--exclude的路径为绝对路径。
/var/www/html/
/var/www/html/4.html
/var/www/html/7.html
/var/www/html/oldboy/
/var/www/html/9.html
/var/www/html/2.html
/var/www/html/5.html
/var/www/html/3.html
/var/www/html/6.html
/var/www/html/10.html
/var/www/html/1.html
/var/www/html/8.html[root@cs6 www]# tar zcvf www.tar.gz /var/www/html/ --exclude=html/oldboy/test
tar: Removing leading `/' from member names #<==打包路径为绝对路径,--exclude的路径为相对路径。
/var/www/html/
/var/www/html/4.html
/var/www/html/7.html
/var/www/html/oldboy/
/var/www/html/9.html
/var/www/html/2.html
/var/www/html/5.html
/var/www/html/3.html
/var/www/html/6.html
/var/www/html/10.html
/var/www/html/1.html
/var/www/html/8.html[root@cs6 www]# tar zcvf www.tar.gz /var/www/html/ --exclude=oldboy/test
tar: Removing leading `/' from member names #<== --exclude的相对路径去择html也可以。
/var/www/html/
/var/www/html/4.html
/var/www/html/7.html
/var/www/html/oldboy/
/var/www/html/9.html
/var/www/html/2.html
/var/www/html/5.html
/var/www/html/3.html
/var/www/html/6.html
/var/www/html/10.html
/var/www/html/1.html
/var/www/html/8.html
打包/etc目录下所有的普通文件
[root@cs6 /]# ls etc
adjtime DIR_COLORS init.d motd [root@cs6 /]# tar zcvf /tmp/etc.tar.gz `find etc/ -type f` #<==使用find找到所有的普通文件,在tar上命令语句中嵌套一个反引号包含的find命令语句。
[root@cs6 /]# ll -h /tmp/etc.tar.gz
-rw-r--r--. 1 root root 8.7M May 12 18:46 /tmp/etc.tar.gz
6.1 tar:打包备份相关推荐
- linux++tar打包目录,linux中tar命令打包目录与排除目录打包linux操作系统 -电脑资料...
本文章来给各位朋友详细介绍关于linux中tar命令打包目录与排除目录打包有需要了解tar命令的使用方法的朋友可进行参考参考, 打包压缩目录很简单如下代码如下复制代码 tar -czf small.t ...
- gzip,bzip2压缩工具及tar打包工具
gzip,bzip2压缩工具及tar打包工具 1.gzip压缩工具 1>参数: -c:将参数的数据输出到屏幕上,可通过数据流重定向来处理 ...
- tar打包时排除一些文件或者目录
From: http://www.blogjava.net/zhyiwww/archive/2012/08/23/386119.html 用tar打包时排除文件: 可以使用-exclude参数 如: ...
- Linux指令:tar打包与压缩
tar命令介绍 1.下面5个参数只能选择其中之一 -c: 建立压缩档案-x: 解压-t: 查看内容-r: 向压缩归档文件末尾追加文件-u: 更新原压缩包中的文件 2.以下参数为可选项,可与上面参数一同 ...
- 四周第五次课(1月6日) 6.5 zip压缩工具 6.6 tar打包 6.7 打包并压缩
四周第五次课(1月6日) 6.5 zip压缩工具 6.6 tar打包 6.7 打包并压缩 tar命令: 可以为linux的文件和目录创建档案.利用tar,可以为某一特定文件创建档案(备份文件),也可以 ...
- linux tar源码,linux之tar命令备份
大家好 我是都百顺 我的QQ:136882447 Linux学习交流群:225961139 官方网站:www.wmphp.com 下讲我来给大家讲解,使用 教程下载地址:http://pan.bai ...
- linux打包tar包命令,Linux tar打包命令详解
Linux 系统中,最常用的归档(打包)命令就是 tar,该命令可以将许多文件一起保存到一个单独的磁带或磁盘中进行归档.不仅如此,该命令还可以从归档文件中还原所需文件,也就是打包的反过程,称为解打包. ...
- tar打包split分割分解拆分大包文件
2010-01-26 12:47 http://hi.baidu.com/hovlj_1130/item/fe21d8342e68aa86c3cf2928 tar打包split分割分解拆分大包文件 有 ...
- linux tar 打包gzip,tar linux 打包 压缩 gzip 命令说明
参数: -c :建立一个压缩档案的参数指令(create 的意思): -x :解开一个压缩档案的参数指令! -t :查看 tarfile 里面的档案! 特别注意,在参数的下达中, c/x/t 仅 ...
最新文章
- linkerd——针对java的为微服务提供可靠性的proxy,服务发现重试LB等
- Learning Perl 8
- RHEL 5.4 安装Oracle 11gR2, 安装篇1...
- 0218互联网新闻 | 《流浪地球》IMAX中国票房破3亿;苹果发力智能家居
- QTP简单框架(6)之脚本编写实例
- Dns-prefetch DNS 预解析优化页面加载速度
- python 泰坦尼克号存活率分析
- w10自动删除文件怎么关了_绝地求生怎么删除新地图_删新沙漠地图文件办法
- [转载] Java 单例(Singleton)类
- 14.凤凰架构:构建可靠的大型分布式系统 --- 资源与调度
- 图像去雾算法(一)相关研究及链接
- MongoDB学习笔记(查询)
- 2018百度之星程序设计大赛初赛B——1004p1m2
- HA-reshacker
- 什么是软件项目验收,软件项目验收测试方法分享
- impala与hive标准差函数的差异
- 匿名管道和命名管道(代码剖析)
- supersu-v2.8.2.zip_术业有专攻:ZIP文件操作模块zipfile
- 多光谱(RGB-T)语义分割2019-RTFNet总结
- form表单及其连用标签总结
热门文章
- 1102示波器使用方法_你知道示波器的探头是怎样工作的吗?示波器探头的使用方法...
- linux批量安装 五大开源软件挨个看,51CTO_Linux运维和管理:自动化监测.pdf
- 怎么看python环境变量配置是否好了验证图片_python 的 tesserocr 模块安装与获取图片验证码...
- dedeampz mysql启动不了_localhost打不开?dedeampz环境启动不了?本地php环境启动失败?...
- 再见Xshell!这个开源的终端工具更酷炫!
- Python赋值、打包和解包,90%人不清楚的知识点!
- 这100道面试题,用来忽悠半吊子面试官
- Python中的魔法属性
- php的long类型转换,[PHP]将RGB或HEX转换为“Long Int”颜色
- web.xml中的ContextLoaderListener和DispatcherServlet区别