如何查找hadoop中是否存在文件夹?

dba5bblo  于 2021-06-02  发布在  Hadoop
关注(0)|答案(2)|浏览(341)

我需要找到输入文件夹位置是否存在于hadoop中。
我使用下面的命令来做同样的事情

hadoop fs -test -d <folder Location>

查询不抛出任何错误,但也没有输出。我已经检查了它的正确和错误的位置。我从文档中了解到,如果位置正确,它应该输出1。

utugiqy6

utugiqy61#

谢谢@mikhail golubtsov。使用上面的提示,我最后修改的shell脚本是

if hadoop fs -test -d  $1 ;
then echo "yeah it's there "
else
echo  "No its not there." 

fi
yuvru6vn

yuvru6vn2#

hdfs dfs -test -d <folder location> 不会输出任何东西,比如 0 或者 1 . 关于退出状态, 0 表示目录存在时的正常情况。 1 表示缺少目录。
下面是一个可以在bash中使用的示例:

hdfs dfs -test -d /tmp && echo 'dir exists' || echo 'sorry, no such dir'

相关问题