我想创建一个目录中所有文件的 tar 文件减去该目录中的子目录,并将该 tar 文件放在子目录之一中。例如,我在 /test 中有几个 .txt 文件,在 /test 中有另一个名为 ArchivedFiles 的目录。我想告诉 tar 命令归档所有 .txt 文件并将其放在 /test/ArchivedFiles 中。
我该怎么做呢?
问问题
1265 次
2 回答
1
tar cf test/foo/test.tar -- `find test -maxdepth 1 -name '*.txt' -type f`
我认为这应该做你想要的。
由于您的 tar 命令的年龄而无法使用的选项是:
find test -maxdepth 1 -type f -name '*.txt' -print0 | tar -cf test/foo/test.tar --null --files-from -
您遇到了问题,因此您可以尝试以下命令:
tar cf test/foo/test.tar `find test -maxdepth 1 -name '*.txt' -type f`
echo tar cf test/foo/test.tar `find test -maxdepth 1 -name '*.txt' -type f`
tar c f test/foo/test.tar `find test -maxdepth 1 -name '*.txt' -type f`
find test -maxdepth 1 -name '*.txt' -type f
并粘贴输出,以便我们可以看到发生了什么。
鉴于 find 也是非常传统的,让我们尝试以下操作:
tar cf test/foo/test.tar test/*.txt
于 2011-06-28T21:15:09.560 回答
0
以下命令将起作用。它会将所有子目录放入 tar,但不会将这些子目录的内容放入 tar。这意味着,如果您将 tar 放入子目录中,您将不必担心它会将自身置于自身内部......
例如,如果要将当前目录中的所有文件放入名为 mytar.tar 的 tar 文件中,该文件位于名为 d1 的子目录中:
tar --no-recursion -cvf d1/mytar.tar *
于 2011-06-28T21:22:58.597 回答