如何删除hadoop目录中的文件(如果存在)?
我正在使用下面的命令来做到这一点。请注意,如果该文件夹中有任何内容,则此操作正常,
hdfs dfs -rm -r /home/user/folder/*
但当文件夹为空时出现错误“:没有此类文件或目录”。
我的要求是如果存在任何内容应该删除。我怎样才能做到这一点?
I am using below command to do that. Please note this is working fine if there are any contents in that folder
hdfs dfs -rm -r /home/user/folder/*
But am getting an error when the folder is EMPTY ": No such file or directory".
My requirement is it should delete any contents if there exists. How can I achieve that ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先使用
-test -d
运行命令,然后运行 &&
来短路rm
命令(如果它不存在)。或者,忽略该错误,因为该路径已被删除。
First run command with
-test -d
then&&
to short-circuit therm
command if it doesn't exist.Alternatively, ignore the error because the path is already deleted.