7

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

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

2 Answers 2

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.

11
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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