Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if directory in HDFS is empty or not

Tags:

hadoop

hdfs

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

like image 864
VSP Avatar asked Mar 03 '17 09:03

VSP


2 Answers

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.

like image 147
franklinsijo Avatar answered Oct 07 '22 17:10

franklinsijo


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
like image 39
Alex Raj Kaliamoorthy Avatar answered Oct 07 '22 17:10

Alex Raj Kaliamoorthy