title: Checking if directory in HDFS already exists or not
body: <p>I am having following directory structure in HDFS, </p>
  
  <pre><code>/analysis/alertData/logs/YEAR/MONTH/DATE/HOURS
  </code></pre>
  
  <p>That is data is coming on houly basis and stored in format of year/month/day/hour.</p>
  
  <p>I have written a shell script in which i am passing path till </p>
  
  <pre><code>"/analysis/alertData/logs"   ( this will vary depending on what product of data i am handling)
  </code></pre>
  
  <p>then shell script go through the year/month/date/hour folders and return the most latest path.</p>
  
  <p>For example:</p>
  
  <pre><code> Directories present in HDFS has following structure: 
  
   /analysis/alertData/logs/2014/10/22/01
   /analysis/alertData/logs/2013/5/14/04
  
   shell script is given path till :   " /analysis/alertData/logs "
  
   it outputs most recent directory :    /analysis/alertData/logs/2014/10/22/01
  </code></pre>
  
  <p>My question is here is how can i validate whether HDFS directory path pass to shell script is valid or not. Lets say i pass a wrong path as input or path which does not exist so how to handle that in shell script. </p>
  
  <p>Sample wrong path can be:  </p>
  
  <pre><code>  wrong path   :  /analysis/alertData ( correct path :  /analysis/alertData/logs/ )
    wrong path   :  /abc/xyz/  ( path does not exit in HDFS )
  </code></pre>
  
  <p>I tried using Hadoop dfs -test -z/-d/-e options did not worked for me. 
  Any suggestion for this.</p>
  
  <p>NOTE : Not posting my original code here, as solution to my problem does not depend on it.</p>
  
  <p>Thanks in advance.</p>