+ -
当前位置:首页 → 问答吧 → tar 排除文件

tar 排除文件

时间:2011-06-24

来源:互联网

目录结构:
/home/oracle/data/
        20110620
                t1.unl
                t2.unl
        20110621
                t1.unl
                t2.unl
cfg       
                a.properties
                b.properties
.cshrc               
       
需要用tar打包data目录下的所有目录结构与文件,但要排除*.unl的文件,这种数据文件有很多。且目录结构深度不一致。

如何使用tar来打包呢?

cd /home/oracle/
tar -cvf data.tar ./* -exclude排除的话,只能指定具体的文件名,现在要排除某一类文件。

如何来实现呢?

作者: gdutllf2006   发布时间: 2011-06-24

回复 gdutllf2006


   

QUOTE:
--exclude=PATTERN      exclude files, given as a PATTERN

作者: yinyuemi   发布时间: 2011-06-24

这两个选项对你有帮助么?

--exclude=PATTERN
           exclude files, given as a PATTERN

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

作者: sk1418   发布时间: 2011-06-24

or :
  1. tar -cvf data.tar $(find . -type f -print0 |xargs -0 -n1 |grep -v \.unl$)
  2. #xargs -0(数字0)
复制代码

作者: yinyuemi   发布时间: 2011-06-24

学习了。

作者: zooyo   发布时间: 2011-06-24

回复 yinyuemi
  1. tar -cvf data.tar $(find /home/oracle/data/ ! -name "*.unl")
复制代码
这样应该就行了吧

作者: where27   发布时间: 2011-06-24

exclude应该是排除一个文件列表的吧,都列上就可以了

作者: ashlv   发布时间: 2011-06-24

回复 where27


    学习!!

作者: yinyuemi   发布时间: 2011-06-24