File count in an HDFS directory

前端 未结 6 1996
攒了一身酷
攒了一身酷 2021-01-31 10:36

In Java code, I want to connect to a directory in HDFS, learn the number of files in that directory, get their names and want to read them. I can already read the files but I co

6条回答
  •  醉酒成梦
    2021-01-31 11:10

    To do a quick and simple count, you can also try the following one-liner:

    hdfs dfs -ls -R /path/to/your/directory/ | grep -E '^-' | wc -l
    

    Quick explanation:

    grep -E '^-' or egrep '^-': Grep all files: Files start with '-' whereas folders start with 'd';

    wc -l: line count.

提交回复
热议问题