linux - tar: 无法将目录更改为 <dir>/<file>: 不是目录

标签 linux unix tar

我需要对这个目录进行 tar - totar:

$ ls -l totar/
total 61388
 292 -rw-r--r--    1 wasext   was          298867 Apr 13 16:44 application.2015-01-19.0.log
 108 -rw-r--r--    1 wasext   was          109623 Apr 14 13:32 application.2015-01-20.0.log
 788 -rw-r--r--    1 wasext   was          805468 Apr 14 13:32 application.2015-01-21.0.log
1080 -rw-r--r--    1 wasext   was         1104861 Apr 14 13:32 application.2015-01-22.0.log
2052 -rw-r--r--    1 wasext   was         2098782 Apr 14 13:32 application.2015-01-23.0.log
   4 -rw-r--r--    1 wasext   was             455 Apr 14 13:32 application.2015-01-24.0.log
21076 -rw-r--r--    1 wasext   was        21581073 Apr 14 13:32 application.2015-01-26.0.log
9296 -rw-r--r--    1 wasext   was         9519026 Apr 14 13:32 application.2015-01-27.0.log
17912 -rw-r--r--    1 wasext   was        18341302 Apr 14 13:32 application.2015-01-28.0.log
8780 -rw-r--r--    1 wasext   was         8989019 Apr 14 13:32 application.2015-01-29.0.log

我使用参数“-C”创建了 tarball 文件:

$ tar cvf t.tar -C totar/*
tar: can't change directories to totar/application.2015-01-19.0.log: Not a directory
a totar/application.2015-01-20.0.log 215 blocks
a totar/application.2015-01-21.0.log 1574 blocks
a totar/application.2015-01-22.0.log 2158 blocks
a totar/application.2015-01-23.0.log 4100 blocks
a totar/application.2015-01-24.0.log 1 blocks
a totar/application.2015-01-26.0.log 42151 blocks
a totar/application.2015-01-27.0.log 18592 blocks
a totar/application.2015-01-28.0.log 35823 blocks
a totar/application.2015-01-29.0.log 17557 blocks

我遇到了这个错误: tar:无法将目录更改为 totar/application.2015-01-19.0.log:不是目录

在创建的 tar 文件中缺少文件:totar/application.2015-01-19.0.log:

$ tar tf t.tar
totar/application.2015-01-20.0.log
totar/application.2015-01-21.0.log
totar/application.2015-01-22.0.log
totar/application.2015-01-23.0.log
totar/application.2015-01-24.0.log
totar/application.2015-01-26.0.log
totar/application.2015-01-27.0.log
totar/application.2015-01-28.0.log
totar/application.2015-01-29.0.log

你能帮我看看我错在哪里吗?

最佳答案

随着 -C tar 的选项,你在告诉tar在将文件添加到存档之前先更改到该目录。这非常方便,可以避免必须更改到该目录才能开始。假设你在你的 $HOME目录并希望将文件归档在 /path/to/totar 中, 那么你只需给出 -C选项到上面的目录totar 和目标目录。如果要存档/path/to/totar , 那么你想:

tar -C /path/to cvf somearchive.tar totar

注意上面的文件规范totar目录名,不是文件名,将包括 totar 中的所有文件目录。您包含通配符,但可以包含特定文件名。仅备份 /path/to/totar 中的部分文件:

tar -C /path/to/totar cvf somearchive.tar filename

filenametotar目录。 (不允许使用通配符)

关于linux - tar: 无法将目录更改为 <dir>/<file>: 不是目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29626435/

相关文章:

linux - 如何限制从 grep 返回的结果数?

bash - 提取出现在特定单词之后的单词

shell - 打印 csv 文件的 2 列

c - 在启动 linux 时以编程方式启动应用程序

linux - 为什么/var/www/需要755权限?为什么chown之后不是700?

linux - ansible 剧本无法继续,因为 `tar` 由于 `file change as we read` 而失败

bash - 错误 : Tar command not found

node.js - 在客户端下载压缩文件夹在 Angular+Node 中不起作用(MEAN)

linux - 是否可以为 `git clone` 操作指定超时?

linux - docker 运行失败