在要归档的目录的子目录中创建一个tar文件
我想创建一个目录中所有文件(减去该目录中的子目录)的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这应该做你想做的。
由于 tar 命令的年龄而无法使用的选项是:
您遇到问题,因此您可以尝试以下命令:
并粘贴输出,以便我们可以看到发生了什么。
鉴于 find 也很传统,让我们尝试以下操作:
I think that should do what you want.
An option which will not work due to the age of your tar command is:
You are having problems, so you can try the following commands:
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 中,但不会将这些子目录的内容放入 tar 中。这意味着,如果您将 tar 放入子目录中,则不必担心它将自身放入自身内部...
例如,如果您想将当前目录中的所有文件放入 tar 中名为 mytar.tar 的文件位于名为 d1 的子目录中:
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: