您的位置:首页 > 大数据 > Hadoop

hdfs判断文件是否存在

2016-10-27 16:08 399 查看
hadoop判断文件是否存在
 
在shell中判断一个HDFS目录/文件是否存在
 
直接看shell代码:
 
hadoop fs -test -e /hdfs_dir
if [ $? -ne 0 ]; then
    echo "Directory not exists!"
fi
hadoop fs -test -e 用于判断HDFS目录/文件是否存在,下一步检测该命令的返回值,以确定其判断结果。
 
-test -[ezd] <path>: If file { exists, has zero length, is a directory
then return 0, else return 1.
 
e,z,d参数必用其一,不可缺少。 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: