8

Is there any command in HDFS to check whether a directory is empty or not

2
  • 1
    hdfs dfs -ls /directory/path/
    – BruceWayne
    Commented Mar 3, 2017 at 9:20
  • hadoop fs -count hdfs:/directory/path/
    – aironman
    Commented Mar 3, 2017 at 9:51

2 Answers 2

12
isEmpty=$(hdfs dfs -count /some/path | awk '{print $2}')
if [[ $isEmpty -eq 0 ]];then
    echo "Given Path is empty"
    #Do some operation
else
    echo "Given Path is not empty"
    #Do some operation
fi
11

count:

hdfs dfs -count /path
           1            0                  0 /path

The output columns are: DIR_COUNT, FILE_COUNT, CONTENT_SIZE, PATHNAME

du:

hdfs dfs -du -s /path
0  /path

If there are 0 byte files or empty directories, the result would still be 0.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.