【问题标题】:How to find if a folder exists in hadoop or not?如何查找hadoop中是否存在文件夹?
【发布时间】:2015-10-18 21:25:06
【问题描述】:

我需要在 hadoop 中查找输入文件夹位置是否存在。

我正在使用以下命令来做同样的事情

 hadoop fs -test -d <folder Location> 

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

【问题讨论】:

    标签: shell hadoop bigdata


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      hdfs dfs -test -d &lt;folder location&gt; 不输出任何内容,例如 01。与退出状态有关,0 代表目录存在时的正常情况。 1 表示缺少目录。

      这是一个可以在 bash 中使用的示例:

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

      【讨论】:

        猜你喜欢
        • 2011-11-15
        • 2013-03-12
        • 1970-01-01
        • 2013-08-24
        • 2010-12-10
        • 1970-01-01
        • 2012-02-05
        • 2022-07-01
        • 1970-01-01
        相关资源
        最近更新 更多