tar:目录:无法rmdir:目录不为空

问题描述 投票:0回答:2

我正在尝试了解使用tar的正确方法是什么。我有一个名为main的目录,在sub目录中它包含一些我要排除的文件和目录。我要删除的所有其他人。我使用的命令:

tar --remove-files --exclude main/sub/.runtime --exclude main/sub/.startTime --exclude main/sub/subsubdir -zcvf main.tar.gz main

但是我得到:

tar: main/sub: Cannot rmdir: Directory not empty
tar: Exiting with failure status due to previous errors

当然,现在main/sub目录不为空(由于排除的文件/目录)。在不将输出重定向到/dev/null或其他方式的情况下,解决该错误的正确方法是什么?我仍然想得到错误,但不是那一个。

linux tar
2个回答
0
投票

首先:

cd main

然后是>>

tar --remove-files --exclude sub/.runtime --exclude sub/.startTime --exclude sub/subsubdir -zcvf main.tar.gz *

这应该防止子目录错误,同样,如果您在脚本中使用它或使用别名:

( cd main;tar --remove-files --exclude sub/.runtime --exclude sub/.startTime --exclude sub/subsubdir -zcvf main.tar.gz * )

((防止它对父外壳执行任何操作,因此您留在目录中


0
投票

可能是--remove-files选项的错误。

© www.soinside.com 2019 - 2024. All rights reserved.