如何删除hadoop目录中的文件(如果存在)?

发布于 2025-01-14 23:17:02 字数 179 浏览 3 评论 0原文

我正在使用下面的命令来做到这一点。请注意,如果该文件夹中有任何内容,则此操作正常,

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

○愚か者の日 2025-01-21 23:17:02

首先使用 -test -d 运行命令,然后运行 ​​&& 来短路 rm 命令(如果它不存在)。

hadoop fs -test -d /home/user/folder && hadoop fs -rm -r /home/user/folder/*

或者,忽略该错误,因为该路径已被删除。

First run command with -test -d then && to short-circuit the rm command if it doesn't exist.

hadoop fs -test -d /home/user/folder && hadoop fs -rm -r /home/user/folder/*

Alternatively, ignore the error because the path is already deleted.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文