Checking if directory in HDFS is empty or not

前端 未结 2 1758
再見小時候
再見小時候 2021-02-09 18:46

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

相关标签:
2条回答
  • 2021-02-09 19:17
    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
    
    0 讨论(0)
  • 2021-02-09 19:37

    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.

    0 讨论(0)
提交回复
热议问题