2015-07-28 64 views
6

我需要查找输入文件夹位置是否存在或不在hadoop中。如何查找文件夹是否存在于hadoop中?

我使用下面的命令做同样的

hadoop fs -test -d <folder Location> 

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

回答

8

hdfs dfs -test -d <folder location>不输出任何东西,如01。这是关于退出状态,0代表目录存在时的正常情况。 1表示缺少目录。

这里是你可以在bash使用它的一个例子:

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

迄今为止所见的最佳工作解决方案... –

3

感谢@Mikhail Golubtsov。使用上述提示我的最终修改后的shell脚本是

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

fi 
相关问题