tar命令中--exclude参数使用详解

tar命令中--exclude参数使用详解

2008-04-07 11:15:33| 分类: linux |字号 订阅
tar --null -P -czf /tmp/archive.tar.gz --files-from=files.lst
files.lst是要打包的文件列表

tar 中--exclude的用法
tar czvf oracle.tar.gz oracle --exclude oracle/oradata --exclude oracle/admin/shvoip --exclude oracle/doc

如何使用tar进行排除一个目录的备份

你打包/home这个目录,/home/123/是你不想打包的目录。
tar cvf my.bak.tar /home --exclude /home/123

tar exclude
Published at February 20, 2008 in C/C++.
搞了半天tar 的exclude 要放在 最後尾端才行:
tar jcvf WLANIntercept_20080220.tar.bz WLANIntercept/ –exclude=Debug



需要备份/home/software/test下内容,
不包含里面的目录005
这样可以备份
#cd /home/software/test
# tar -cvzf test.tar.gz . --exclude=005
./
./001
./002
./003
./004
./008
./test.tar.gz
如果回到上一层目录,
cd ../就是在/home/software
# tar -cvzf test.tar.gz --exclude=test/005/ test
test/
test/001
test/002
test/003
test/004
test/005/
test/005/006
test/005/007
test/008
test/test.tar.gz
exclude却没有作用????

如果按照最上面的成功的方法,如果解压,就直接把test下的内容解到了
当前目录。。。。
第二总方法为什么有问题???
请指点。。。。。。

求助tar备份中exclude的问题

晕,已解决
# tar -cvzf test.tar.gz --exclude=test/005/ test
# tar -cvzf test.tar.gz --exclude=test/005 test
这两个效果是绝对不一样的。


tar命令有个–exclude参数,当你打包要排除掉某些特征的文件时就需要用它了,–exclude参数支持’PATTERN’匹配,可以灵活的指定要排除的范围,详细用法见以下文档,英文的(没找到中文的),我懒得翻译了,呵呵。

————————————————————————————-

Excluding Some Files ====================
*(This message will disappear, once this node revised.)*
This option causes `tar' to read a list of regular expressions (in shell wildcard syntax), one per line, From FILE; `tar' will ignore files matching those regular expressions. Thus if `tar' is called as `tar -c -X foo .' and the file `foo' contains a single line `*.o', no files whose names end in `.o' will be added to the archive. Multiple `--exclude=PATTERN' options may be given.
The `--exclude=PATTERN' option will prevent any file or member which matches the regular expression PATTERN From being operated on. For example, if you want to create an archive with all the contents of `/tmp' except the file `/tmp/foo', you can use the command `tar --create --file=arch.tar --exclude=foo'.
If there are many files you want to exclude, you can use the `--exclude-from=FILE-OF-PATTERNS' (`-X FILE-OF-PATTERNS') option. This works just like the `--files-from=FILE-OF-NAMES' (`-T FILE-OF-NA

MES') option: specify the name of a file as EXCLUDE-LIST which contains the list of patterns you want to exclude.
To avoid operating on files whose names match a particular pattern, use the `--exclude=PATTERN' or `--exclude-from=FILE-OF-PATTERNS' (`-X FILE-OF-PATTERNS') options. When you specify the `--exclude=PATTERN' option, `tar' ignores files which match the PATTERN, which can be a single file name or a more complex expression. Thus, if you invoke `tar' with `tar --create --exclude=*.o', no files whose names end in `.o' are included in the archive.
A PATTERN should be written according to shell syntax, using wildcard characters to effect globbing. Most characters in the pattern stand for themselves in a file name, and case is significant: `a' will match only `a', and not `A'. The character `?' in the pattern matches any single character in the file name. The character `*' in the pattern matches zero, one or more single characters in the file name. The character `[', up to the matching `]', introduces a character class, and is described in the next paragraph. The character `\' in a pattern merely introduces the following character of the pattern as matching a single character in the file name; it is useful when one needs to match `?', `*', `[' or `\' themselves.
A character class is a list of acceptable characters for the next single character of the file name. However, if the first character of the class, just after the opening `[', is `!' or `^', then the meaning of the class is reversed, and it rather lists those characters which are *forbidden* as the next single character of the file name. Other characters of the class stand for themselves. The special construction `L-M', using an hyphen between two letters, is meant to represent all characters between L and M included.
Periods (`.') or slashes (`/') are not considered special for wildcard matches. However, if a pattern completely matches a directory prefix of a file name, then it matches the full file name: that is to say that that excluding a directory also excludes all the files beneath it.
`--exclude-from=FILE-OF-PATTERNS' (`-X FILE-OF-PATTERNS') acts like `--exclude=PATTERN', but specifies a file FILE containing a list of patterns. `tar' ignores files with names that fit any of these patterns.
You can use either option more than once in a single command.
`--exclude=PATTERN' Causes `tar' to ignore files that match the PATTERN.
`--exclude-from=FILE' `-X FILE' Causes `tar' to ignore files that match the patterns listed in FILE.
Even if exclude options are somewhat straightforward, a few users find them confusing. Collected out of a few reports we received, here is a list of more common pitfalls.
* On the command line invoking `tar', after all options, there is an explicit list of files or directories to handle. If any such file is directly subject to an exc

lusion due to `--exclude=PATTERN' or {No Value For "op-exclude-file"}, then the explicit file prevails over the exclusion. You may consider that exclusion is effected while directories are recursively traversed, but not at the top level.
* One can sometimes mix the meaning of `--exclude=PATTERN' and `--exclude-from=FILE-OF-PATTERNS' (`-X FILE-OF-PATTERNS'). Be careful to use `--exclude=PATTERN' when files to be excluded are given as a pattern on the command line, and to use `--exclude-from=FILE-OF-PATTERNS' (`-X FILE-OF-PATTERNS') for introducing the name of a file, itself containing a list of patterns, one per line, each of these patterns being able to exclude zero, one or many files.
* When using `--exclude=PATTERN', be sure to quote the PATTERN parameter, so GNU `tar' see wildcard characters like `*'. If you do not do this, the shell might expand the `*' itself using files at hand, so `tar' might receive a list of files instead of one pattern, or none at all, making the command somewhat illegal. This might not correspond to what one wants. For example, write:
tar --create --file=ARCHIVE.tar --exclude='*/tmp/*' DIRECTORY
rather than:
tar --create --file=ARCHIVE.tar --exclude=*/tmp/* DIRECTORY
* Exclude options in `tar' use shell syntax, or globbing, rather than `regexp' syntax. Using `regexp' syntax to describe files to be excluded will generally not yield the expected behavior.
* In releases of GNU `tar' prior to 1.11.8, long options and old options could not be safely mixed on a single `tar' invocation, so the `--exclude=PATTERN' option was not recognized as such, for the common case old options were used.
* We found out that what is currently the `--exclude-from' option used to be called `--exclude' instead, in some previous version of GNU `tar', at a time before the current `--exclude' option

相关文档
最新文档