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 [ ...
随机推荐
- springboot项目整合mybatis
记录创建springboot项目并配置mybatis中间件: 资源准备及版本说明 编程工具:IDEA JDK版本:1.8 Maven版本:Apache Maven 3.6.3 springboot版本 ...
- electron项目踩坑--A JavaScript error occurred in the main process:document is not defined
前言 记录electron-vue项目开发中遇到的一个错误,运行时报错如图: 控制台报错如下: ReferenceError: document is not defined at Object.&l ...
- Salesforce学习之路(九)Org的命名空间
1. 命名空间的适用场景 每个组件都是命名空间的一部分,如果Org中设置了命名空间前缀,那么需使用该命名空间访问组件.否则,使用默认命名空间访问组件,系统默认的命名空间为"c". ...
- 为什么 DNS 协议使用 UDP?只使用了 UDP 吗?
尽人事,听天命.博主东南大学硕士在读,携程 Java 后台开发暑期实习生,热爱健身和篮球,乐于分享技术相关的所见所得,关注公众号 @ 飞天小牛肉,第一时间获取文章更新,成长的路上我们一起进步 本文已收 ...
- 1019 General Palindromic Number
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- SpringAOP_构造注入实现
SpringAOP_构造注入实现 AOP_面向切面编程初步了解 让我们先想象一个场景,你正在编写一个项目,在开发过程中的多个模块都有某段重复的代码,于是你选择将其抽象成一个方法,然后在需要的地方调用这 ...
- hdu4810
题意: 给你n个数,让你输出n个数,没一次输出的是在这n个数里面取i个数异或的和(所有情况<C n中取i>). 思路: 首先把所有的数都拆成二进制,然后把他们在某一位上 ...
- 6.PHP与JavaScript交互
PHP与JS交互 JS年闰年判断(body里直接引用JS) <form name="form1" method="post" action="& ...
- MinGW 可以编译驱动的
#include <ddk/ntddk.h> static VOID STDCALLmy_unload( IN PDRIVER_OBJECT DriverObject ) {} NTSTA ...
- C#-窗体鼠标穿透
#region 窗体鼠标穿透 private const uint WS_EX_LAYERED = 0x80000; private const int WS_EX_TRANSPARENT = 0x2 ...