我们创建以下bash脚本
此脚本将计算每个hdfs文件夹下的文件数
# !/bin/bash
hadoop dfs -lsr / 2>/dev/null| grep drwx |awk '{print $NF}'>/tmp/file
while read -r line
do
sleep 0.1
echo -n $line
su -l hdfs -c "hdfs fsck $line -files -blocks -locations -openforwrite 2>/dev/null| grep 'Total files' "
done < /tmp/file
输出示例
/applications Total files: 34198
/applications/hdfs Total files: 34185
/applications/hive Total files: 13
/apps Total files: 230
/apps/hive Total files: 443540
这个脚本的问题是扫描所有hdfs和子hdfs文件夹(递归)并最终打印文件所需的时间
还有什么好主意能让文件在hdfs中的计数比我的方式快得多吗?
暂无答案!
目前还没有任何答案,快来回答吧!