我正在尝试了解使用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
或其他方式的情况下,解决该错误的正确方法是什么?我仍然想得到错误,但不是那一个。
首先:
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 * )
((防止它对父外壳执行任何操作,因此您留在目录中
可能是--remove-files
选项的错误。