我需要对这个目录进行 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
仅filename
在totar
目录。 (不允许使用通配符)
关于linux - tar: 无法将目录更改为 <dir>/<file>: 不是目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29626435/