Linux tar命令exclude选项排除指定文件或目录
在linux中可以用tar打包目录以方便传输or备份,我们先来看一个例子
test 文件夹有如下文件
- [root@lee ~]# ll test
- 总用量
- -rw-r--r--. root root 4月 : a.jpg
- -rw-r--r--. root root 4月 : a.log
- -rw-r--r--. root root 4月 : a.txt
- -rw-r--r--. root root 4月 : b.jpg
- -rw-r--r--. root root 4月 : b.log
- -rw-r--r--. root root 4月 : b.txt
- drwxr-xr-x. root root 4月 : dir1
- drwxr-xr-x. root root 4月 : dir2
打包
- [root@lee ~]# tar -cvf test.tgz test/
- test/
- test/b.jpg
- test/b.txt
- test/dir2/
- test/b.log
- test/dir1/
- test/dir1/b.txt
- test/dir1/a.txt
- test/a.jpg
- test/a.txt
- test/a.log
这样是打包全部文件,我们需要排除jpg文件可以这么弄
- [root@lee ~]# tar -cvf test.tgz test/ --exclude *.jpg
- test/
- test/b.txt
- test/dir2/
- test/b.log
- test/dir1/
- test/dir1/b.txt
- test/dir1/a.txt
- test/a.txt
- test/a.log
- [root@lee ~]#
这样,就会把jpg后缀的文件都排除了,包括子目录!
如果是多个后缀类型需要被排除可以在后面添加,无限制
- [root@lee ~]# tar -cvf test.tgz test/ --exclude *.txt --exclude *.jpg
- test/
- test/dir2/
- test/b.log
- test/dir1/
- test/a.log
- [root@lee ~]#
以上是匹配排除某个文件类型后缀,也可以直接指定文件名
- [root@lee ~]# tar -cvf test.tgz test/ --exclude a.txt
- test/
- test/b.jpg
- test/b.txt
- test/dir2/
- test/b.log
- test/dir1/
- test/dir1/b.txt
- test/a.jpg
- test/a.log
- [root@lee ~]#
或者指定目录
- [root@lee ~]# tar -cvf test.tgz test/ --exclude dir1
- test/
- test/b.jpg
- test/b.txt
- test/dir2/
- test/b.log
- test/a.jpg
- test/a.txt
- test/a.log
- [root@lee ~]#
也可以排除目录与文件一起混合使用,如:
- [root@lee ~]# tar -cvf test.tgz test/ --exclude dir1 --exclude a.log --exclude *.jpg
- test/
- test/b.txt
- test/dir2/
- test/b.log
- test/a.txt
- [root@lee ~]#
Linux tar命令exclude选项排除指定文件或目录的更多相关文章
- find tar排除指定文件或目录操作及查找文件内容关键字
1.find查找排除单个目录 查找当前目录或者子目录下所有.txt文件,但是跳过子目录sk find . -path "./sk" -prune -o -name "*. ...
- (转)使用 linux tar 命令压缩与解压文件
原文链接 http://www.cnblogs.com/qq78292959/archive/2011/07/06/2099427.html tar -c: 建立压缩档案-x:解压-t:查看内容-r: ...
- Rsync多模块复制、排除指定文件及目录以及数据无差异复制的应用实例
在我的博客<Rsync 数据复制软件应用>中,拉取数据访问的都是服务器端的/backup 目录,当然我们在其他目录下拉取数据.而实现这种操作就是指多模块复制. 要实现多模块复制首先需要修改 ...
- linux基础命令学习(二)文件和目录操作
1.变换当前目录(change directory) cd /home 进入 '/ home' 目录' (change directory) cd .. 返回上一级目录 cd .. ...
- Linux tar命令之--exclude参数 排除指定的文件或目录
https://my.oschina.net/u/3285916/blog/1632552 参数: --exclude 打包时排除不需要处理的文件或目录 说明: tar -zcf a.tar.gz 打 ...
- [转载] linux下tar命令解压到指定的目录
参考 http://blog.sina.com.cn/s/blog_62449fcf0100nfar.html linux下tar命令解压到指定的目录 : #tar zxvf /bbs.tar.z ...
- linux下tar命令解压到指定的目录
linux下tar命令解压到指定的目录 : #tar zxvf xx.tar.gz -C /xx//把根目录下的xx.tar.gz解压到/xx/下,前提要保证存在/xx这个目录 这个和cp命令有点不同 ...
- Linux tar命令高级用法——备份数据
Linux tar命令高级用法——备份数据 2015-12-31 Linux学习 Linux上有功能强大的tar命令,tar最初是为了制作磁带备份(tape archive)而设计的,它的作用是把文件 ...
- Linux操作系统常用命令合集——第一篇-文件和目录操作(40个命令)
一.选项和参数的区别 在经过上一次的系统安装后我们已经成功登陆,登陆LInux后,我们就可以在#或$符后面去输入命令,有的时候命令后面还会跟着“选项”(英文名:options)或“参数” ...
随机推荐
- iBATIS sqlMapConfig配置详解
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE sqlMapConfig PUBLIC & ...
- hdu4547 lca tarjan
比较直接. #include<map> #include<queue> #include<stack> #include<cmath> #include ...
- POJ2437 Muddy roads
Description Farmer John has a problem: the dirt road from his farm to town has suffered in the recen ...
- junit加载
Run as junit 不会出现,把junit 包倒入lib文件夹中,在类的后面加上extends TestCase,此时上方会导入一个包:import junit.framework.TestCa ...
- ci控制器写规范
不需要后缀名 文件名全部小写 所有控制器需要直接或者间接继承CI_Controller 以下划线开头的方法为私有方法,不能被请求 protected private的方法不能被浏览器请求 ci方法名不 ...
- ECSHOP用户协议字体颜色更改
ECSHOP用户协议字体颜色更改 ECSHOP教程/ ecshop教程网(www.ecshop119.com) 2013-11-12 ECSHOP用户协议模板文件article_pro.dwt 这 ...
- 漂亮的title提示信息
<HTML> <HEAD> <title>一种很酷的文字提示效果演示</title> <style> .tableBorder7{width ...
- C++ 中map 中迭代器的简单使用:
public member function <map> std::map::find iterator find (const key_type& k); const_itera ...
- jQuery1.11源码分析(6)-----jQuery结构总揽
(在看以下内容之前请先对原型链有一定的了解,比如:prototype是对象还是函数?) 在看jQuery的其他源码之前,必须对jQuery的数据结构有一定的了解. jQuery的核心很简单,jQuer ...
- [整理]Code::Blocks使用遇到的问题
在使用其编写C小程序的过程总会遇到些问题,特整理如下: 1.无法调试 注意的是项目所在的文件路径不能包含中文. 2.头文件接口函数申明引用无效 查看头文件是否处于可编译状态,左侧项目文件列表里是文件名 ...