Checking if directory in HDFS already exists or not Checking if directory in HDFS already exists or not hadoop hadoop

Checking if directory in HDFS already exists or not


Try w/o test command []:

if $(hadoop fs -test -d $yourdir) ; then echo "ok";else echo "not ok"; fi


Since

hdfs dfs -test -d $yourdir

return 0 if exists, then

if [ $? == 0 ]; then    echo "exists"else    echo "dir does not exists"fi


Hadoop fs is deprecatedUsage: hdfs dfs -test -[ezd] URI

Options:The -e option will check to see if the file exists, returning 0 if true.The -z option will check to see if the file is zero length, returning 0 if true.The -d option will check to see if the path is directory, returning 0 if true.Example: hdfs dfs -test -d $yourdir

Please check the following for more info: https://hadoop.apache.org/docs/r2.4.1/hadoop-project-dist/hadoop-common/FileSystemShell.htmlRegards