Hello Mark,

The command is to be used by testing the return code observed:

Option | Meaning | Success code | Failure code

-d | directory test | 0 | 1
-e | exists test | 0 | 1
-z | empty file test | 0 | 1

For non existent files or other errors, 255 is returned.

In the shell, you can use $? to check return code of a command, and then run 
conditions on it as you'd like.

Here's a sample way to use this (I have a dir 'examples' and a file 
'README.txt'):

➜  ~HADOOP_HOME  hadoop dfs -test -d examples    
➜  ~HADOOP_HOME  echo $?
0
➜  ~HADOOP_HOME  hadoop dfs -test -d README.txt
➜  ~HADOOP_HOME  echo $?                       
1


On 13-Jan-2012, at 9:19 PM, Pundurs, Mark wrote:

> When using v0.20.2, the script command
> 
> echo "test result is >$( bin/hadoop dfs -test -d $FILEPATH )<"
> 
> gives the following output whether FILEPATH is a directory or a file:
> 
> test result is ><
> 
> Is this a known issue in 0.20.2? Or am I missing the point of -test -d? Or = 
> what?
> 
> Mark Pundurs
> Data Analyst - Traffic
> Nokia Location & Commerce
> 
> 
> The information contained in this communication may be CONFIDENTIAL and is 
> intended only for the use of the recipient(s) named above.  If you are not 
> the intended recipient, you are hereby notified that any dissemination, 
> distribution, or copying of this communication, or any of its contents, is 
> strictly prohibited.  If you have received this communication in error, 
> please notify the sender and delete/destroy the original message and any copy 
> of it from your computer or paper files.

Reply via email to