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 [ ...
随机推荐
- Spring Boot demo系列(三):Spring Web+MyBatis Plus
2021.2.24 更新 1 概述 Spring Web+MyBatis Plus的一个Demo,内容和上一篇类似,因此重点放在MyBatis Plus这里. 2 dao层 MyBatis Plus相 ...
- Arch! 从安装开始
Arch! 从安装开始 事实上Arch的安装Arch Wiki Installation Guide,已经非常详细了 但是初次面对这些东西时肯定非常迷茫,根本不知道这些东西是在干嘛?为什么要这么干? ...
- Java中常见方法详解合集(方法的定义及语法结构)
Java的方法定义 1.方法的定义 方法是控制对象的动作行为方式与准则,在Java中方法位于类体下又有另一种含义. 普通的方法在类中称为"实例方法",因为方法的调用需要创建对象,而 ...
- Spring Boot 轻量替代框架 Solon 1.3.29 发布
Solon 是一个微型的Java开发框架.项目2018年启动,参考过大量前人作品:内核0.1m的身材,超高的跑分,以及良好的使用体验.支持:RPC.REST API.MVC.WebSocket.Soc ...
- vue.js中$emit的理解
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...
- 如何让c语言使用结构体近似模拟c++中的类
如今统治市场的主流编程语言,如c++,java,大都是面向对象类型的编程语言. 而众所周知,c语言是面向过程的编程语言,但是它拥有一个类似于类的结构,叫做结构体,主要的区别在于结构体无法定义函数. 因 ...
- CVE-2013-2551:Internet Explore VML COALineDashStyleArray 整数溢出漏洞简单调试分析
0x01 2013 Pwn2Own 黑客大赛 在 Pwn2Own 的黑客大赛上,来自法国的 VUPEN 安全团队再一次利用 0day 漏洞攻破 Windows8 环境下的 IE10 浏览器,这一次问题 ...
- Windows核心编程 第九章 线程与内核对象的同步(下)
9.4 等待定时器内核对象 等待定时器是在某个时间或按规定的间隔时间发出自己的信号通知的内核对象.它们通常用来在某个时间执行某个操作. 若要创建等待定时器,只需要调用C r e a t e Wa i ...
- 神经网络与机器学习 笔记—多层感知器(MLP)
多层感知器(MLP) Rosenblatt感知器和LMS算法,都是单层的并且是单个神经元构造的神经网络,他们的局限性是只能解决线性可分问题,例如Rosenblatt感知器一直没办法处理简单异或问题.然 ...
- 微信小程序中的加载更多(即列表分页)
1.app.json中: "window": { "enablePullDownRefresh": true //是否开启当前页面下拉刷新 } 2.wxml中: ...