以下是我尝试过的脚本的一个片段
压缩子目录中的所有 php 文件。它尝试使用“--include”参数
但似乎不起作用(输出来自 bash 中的“set -x”)
+ find . -name '*.php'
./autoload.php
./ext/thrift_protocol/run-tests.php
./protocol/TBinaryProtocol.php
...
./transport/TTransportFactory.php
+ tar -cvjf my.tar.bz2 '--include=*.php' .
+ set +x
find
找到了几个 php 文件,但 tar 似乎没有看到它们。如果我取出 --include
所有文件都被 tar 化。我知道我可以使用 find 来提供列表
(
find . -name '*.php' -print0 | tar -cvjf "my.tar.bz2" --null -T -
),但是 --include
有什么问题参数?
最佳答案
GNU tar 有一个 -T or --files-from option可以获取包含要包含的文件列表的文件。使用此选项指定的文件可以是标准输入的“-”。因此,您可以使用 将任意文件列表传递给 tar 以从标准输入存档。 -文件来自 - .使用 查找 模式来生成文件列表,您的示例变为:
find . -name '*.php' -print0 | tar -cvjf my.tar.bz2 --null --files-from -
关于带有 --include 模式的 tar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5747755/