VSP
VSP

Reputation: 293

Checking if directory in HDFS is empty or not

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

Upvotes: 8

Views: 13785

Answers (2)

Alex Raj Kaliamoorthy
Alex Raj Kaliamoorthy

Reputation: 2095

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

Upvotes: 12

franklinsijo
franklinsijo

Reputation: 18270

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.

Upvotes: 11

Related Questions