在要归档的目录的子目录中创建一个tar文件

发布于 2024-11-17 20:46:17 字数 184 浏览 10 评论 0原文

我想创建一个目录中所有文件(减去该目录中的子目录)的 tar 文件,并将该 tar 文件放置在子目录之一中。例如,我在 /test 中有几个 .txt 文件,在 /test 中有另一个名为 ArchivedFiles 的目录。我想告诉 tar 命令存档所有 .txt 文件并将其放置在 /test/ArchivedFiles 中。
我该怎么做呢?

I'd like to create a tar file of all the files in a directory minus sub-directory's in that directory and place that tar file in one of the sub-directory's. For example, I have several .txt files in /test and also another directory in /test called ArchivedFiles. I'd like to tell the tar command to archive all of the .txt files and place it in /test/ArchivedFiles.
How do I go about doing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

坐在坟头思考人生 2024-11-24 20:46:17
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
tar cf test/foo/test.tar -- `find test  -maxdepth 1 -name '*.txt' -type f`

I think that should do what you want.

An option which will not work due to the age of your tar command is:

find test -maxdepth 1 -type f -name '*.txt' -print0 | tar -cf test/foo/test.tar --null --files-from -

You are having problems, so you can try the following commands:

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

And pastebin the output so that we can see what is happening.

Given that find is very legacy as well, let us try the following:

tar cf test/foo/test.tar test/*.txt
无声静候 2024-11-24 20:46:17

以下命令将起作用。它将把任何子目录放入 tar 中,但不会将这些子目录的内容放入 tar 中。这意味着,如果您将 tar 放入子目录中,则不必担心它将自身放入自身内部...

例如,如果您想将当前目录中的所有文件放入 tar 中名为 mytar.tar 的文件位于名为 d1 的子目录中:

tar --no-recursion -cvf d1/mytar.tar *

The following command will work. It will place any subdirectories into the tar but it doesn't put the contents of those subdirectories into the tar. This means that if you put the tar into a subdir you won't have to worry about it putting itself inside itself inside itself...

For example, if you want to put all of the files which are in the current directory into a tar file called mytar.tar which is in a subdir called d1:

tar --no-recursion -cvf d1/mytar.tar *
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文