Is there any command in HDFS to check whether a directory is empty or not
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
.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With