Is there any command in HDFS to check whether a directory is empty or not
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
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
.