转载自:
http://www.vktone.com/articles/linux-tar-ignore-some-files.html

在Linux下,常用tar对文件或目录归档压缩,有时候需要忽略某些文件或目录,怎么做呢?

原来,tar命令有个长参数 --exclude 可以用来指定排除掉的文件目录。

[root@mos178 usr]# ls motix
bin bin.1153887679 bin.20080407zhy_something_wrong cfg cfg.1153887679 cfg.20070425.tar.gz log motix0405.tar.gz run
[root@mos178 usr]# tar zcf motix.20130121a.tar.gz motix --exclude log --exclude "*.gz"
[root@mos178 usr]# tar ztvf motix.20130121a.tar.gz
...
[root@mos178 usr]#

关键是要总结出要忽略文件的模式来。

[root@sunrise root]# tar zcf work181.20130121a.tar.gz work181 --exclude log --exclude "*20*" --exclude bin 
[root@sunrise root]#

与tar --exclude相关的参数说明如下:

 --exclude PATTERN
exclude files based upon PATTERN

-X, --exclude-from FILE
exclude files listed in FILE

--wildcards
use wildcards with --exclude

--wildcards-match-slash
wildcards match slashes (/) with --exclude

--no-anchored
match any subsequenceof the name’s components with --exclude

--no-ignore-case
use case-sensitive matching with --exclude

--no-wildcards
don’t use wildcards with --exclude

--no-wildcards-match-slash
wildcards do not match slashes (/) with --exclude
 


更多相关文章

  1. 如何查找特定用户可执行的所有文件(不是最新的)
  2. 使用/proc/meminfo文件查看内存状态信息
  3. linux下socket通信常用的结构与头文件
  4. ldconfig报错 :libstdc++.so.6.0.18-gdb.py不是一个elf文件
  5. 有什么办法可以在Windows上不用使用太繁琐的办法从Linux服务器上
  6. linux下touch命令也可以一次创建多个文件和mkdir一次创建多个文
  7. linux目录结构详细介绍
  8. Linux实用程序编写了一个matlab .mat文件
  9. arm-linux学习笔记3-linux内存管理与文件操作

随机推荐

  1. Hystrix Dashboard:断路器执行监控
  2. 带你搭一个SpringBoot+SpringData JPA的D
  3. Spring Cloud Consul:服务治理与配置中心
  4. IDEA中创建和启动SpringBoot应用的正确姿
  5. 使用Logic App进行Azure安全中心工作流自
  6. Spring Cloud OpenFeign:基于 Ribbon 和 H
  7. Python查询迪斯尼\环球公园\海洋世界的
  8. 一行代码的Python GUI弹框
  9. Spring Cloud Zuul:API网关服务
  10. Spring Cloud Gateway:新一代API网关服务