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:打包备份的更多相关文章
- MySQL数据物理备份之tar打包备份
复制数据文件方式,可以使用cp或tar 1.停止服务 [root@localhost mysql]# systemctl stop mysqld [root@localhost mysql]# net ...
- linux下rsync和tar增量备份梳理
前面总结过一篇全量备份/增量备份/差异备份说明,下面介绍下linux下rsync和tar两种增量备份的操作记录: 1)rsync备份 rsync由于本身的特性,在第一次rsync备份后,以后每次都只是 ...
- 烂泥:CentOS命令学习之tar打包与解压
本文由秀依林枫提供友情赞助,首发于烂泥行天下. tar命令一般是做打包和解压使用,有关tar命令的使用.我们可以通过帮助文档进行查看,如下: tar –help man tar tar有几个比较重要的 ...
- Linux tar打包命令
Linux tar打包命令: 范例一:将整个 /etc 目录下的文件全部打包成为 /tmp/etc.tar [root@linux ~]# tar -cvf /tmp/etc.tar /etc < ...
- linux中tar 打包指定路径文件
linux中tar打包指定路径文件www.111cn.net 编辑:yahoo 来源:转载在linux系统中打包与解压文件我都可以使用tar命令来解决,只要使用不同的参数就可以实现不同的需要了,下面来 ...
- tar打包如何不打包某一个文件夹(排除某些文件夹)
tar打包如何不打包某一个文件夹(排除某些文件夹) 问题描述: 最近想备份一下Tomcat运行的的功能文件,以防特殊情况的发生.但是在实际操作的过程中发现,可能是由于Unix/Linux版本太老的原因 ...
- tar --打包和压缩
tar 参考链接 作用:为linux的文件和目录创建档案,也可以在档案中改变文件,或者向档案中加入新的文件即用来压缩和解压文件.tar本身不具有压缩功能.他是调用压缩功能实现的 语法:tar[必要参 ...
- tar打包时的排除选项
1. 在命令行排除文件时,用 --exclude, 可以用多个--exclude . 可以用=号,也可以不用 如 tar -cvf ./aaa.tar ./tvc --exclude ...
- zip压缩工具 tar打包 打包并压缩
6.5 zip压缩工具 6.6 tar打包 6.7 打包并压缩 zip压缩工具 xz,bzip2,gzip都不支持压缩目录 zip可以压缩目录 压缩文件 zip 2.txt.zip 2.txt [ ...
随机推荐
- 树莓派WIFI
树莓派WIFI设置 在"开始使用树莓派"中,我们在boot根目录下创wpa_supplicant.conf文件,实现了第一次连接wifi.以后开机后,树莓派会自动连接那个wifi. ...
- 【笔记】《Redis设计与实现》chapter8 对象
8.1 对象的类型与编码 Redis中的每个对象都由一个redisObject结构表示,该结构中和保存数据有关的三个属性分别是type属性.encoding属性和ptr属性 typedef struc ...
- xss-labs全关教程
0x01 Level 1 查看源码,可以看到接收了name参数,并直接嵌入到HTML页面中了 没有任何过滤,而且直接会当作代码执行. 0x02 Level 2 先传入<script>ale ...
- Jsoup-基于Java实现网络爬虫-爬取笔趣阁小说
注意!仅供学习交流使用,请勿用在歪门邪道的地方!技术只是工具!关键在于用途! 今天接触了一款有意思的框架,作用是网络爬虫,他可以像操作JS一样对网页内容进行提取 初体验Jsoup <!-- Ma ...
- [重要更新]微信小程序登录、用户信息相关接口调整:使用 wx.getUserProfile 取代 wx.getUserInfo
2021年2月24日,微信官方团队发布了一个调整通知:<小程序登录.用户信息相关接口调整说明>,公告明确从4月13日起,所有发布的小程序将无法使用 wx.getUserInfo 接口(JS ...
- I - 树的直径 POJ - 1383
The northern part of the Pyramid contains a very large and complicated labyrinth. The labyrinth is d ...
- 大数翻倍法求解CRT
目录 正文 引入 大数翻倍法 复杂度证明 大数翻倍法的优势 最后的最后:上代码! 注:做法和思路是 zhx 在一次讲课中提出的,如有侵权,请联系作者删除 其实别的题解也有提到过暴力做法,但这里将会给出 ...
- 分解uber依赖注入库dig-使用篇
golang的依赖注入库非常的少,好用的更是少之又少,比较好用的目前有两个 谷歌出的wire,这个是用抽象语法树在编译时实现的. uber出的dig,在运行时,用返射实现的,并基于dig库,写了一个依 ...
- 【JVM】空间分配担保机制
抛几个问题: 1.谁进行空间担保? JVM使用分代收集算法,将堆内存划分为年轻代和老年代,两块内存分别采用不同的垃圾回收算法,空间担保指的是老年代进行空间分配担保 2.什么是空间分配担保? 在发生Mi ...
- 关于 C/C++ 函数调用约定
关于 C/C++ 函数调用约定,大多数时候并不会影响程序逻辑,但遇到跨语言编程时,了解一下还是有好处的. VC 中默认调用是 __cdecl 方式,Windows API 使用 __stdcall 调 ...