没有一些文件夹如何创建tar存档?

时间:2011-12-13 16:56:09

标签: linux tar

如何在没有某些文件夹的情况下创建tar存档?

现在我正在创建文件夹的tar存档并从中删除一些文件夹。但这需要很长时间。

结构:

www
   - sub f 1
   - sub f 2
   - sub f 3

需要仅使用文件夹(子f 1)和(子f 2)创建存档 (仅举例来说,我真正的结构有更多的子级别)

谢谢!

2 个答案:

答案 0 :(得分:8)

这有用吗?

tar -cf backup.tar --exclude "www/subf3" www
// is your directory with spaces?

答案 1 :(得分:2)

Ajreal建议的--exclude选项外,您还可以使用其他tar选项(来自--help输出):

  --exclude=PATTERN      exclude files, given as a PATTERN
  --exclude-backups      exclude backup and lock files
  --exclude-caches       exclude contents of directories containing
                         CACHEDIR.TAG, except for the tag file itself
  --exclude-caches-all   exclude directories containing CACHEDIR.TAG
  --exclude-caches-under exclude everything under directories containing
                         CACHEDIR.TAG
  --exclude-tag=FILE     exclude contents of directories containing FILE,
                         except for FILE itself
  --exclude-tag-all=FILE exclude directories containing FILE
  --exclude-tag-under=FILE   exclude everything under directories
                         containing FILE
  --exclude-vcs          exclude version control system directories
-X, --exclude-from=FILE    exclude patterns listed in FILE

你还可以使用tardy,一个tar后处理器(packaged in Debian