目录中的子目录数量? [英] Number of subdirectories in a directory?

查看:167
本文介绍了目录中的子目录数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述






当我执行<$ c $时,如何在HDFS的指定目录中找到子目录的数目? c> hadoop fs -ls / mydir / ,我得到一个Java堆空间错误,因为该目录太大,但我感兴趣的是该目录中的子目录数。我试过:

  gsamaras @ gwta3000〜] $ hadoop fs -find / mydir / -maxdepth 1 -type d -print | wc -l 
find:意外的参数:-maxdepth
0

我知道该目录不是空的,因此0是不正确的:

  [gsamaras @ gwta3000〜] $ hadoop fs -du -s -h / mydir 
737.5 G / mydir


解决方案

要使用的命令是:
hdfs dfs -ls -R / path / to / mydir / | grep^ d| wc -l <​​/ code>



但是这也会给你错误 java.lang.OutOfMemoryError:Java heap space 。为了避免错误,您需要增加java堆空间并运行相同的命令:

export HADOOP_CLIENT_OPTS =$ HADOOP_CLIENT_OPTS - Xmx5g然后

hdfs dfs -ls -R / path / to / mydir / grep^ d| wc -l <​​/ code> .....#对于所有子目录



OR



hdfs dfs -ls / path / to / mydir / | grep^ d| wc -l <​​/ code> .....#对于maxdepth = 1


How to find the number of subdirectories in a specified directory in HDFS?


When I do hadoop fs -ls /mydir/, I get a Java heap space error, since the directory is too big, but what I am interested in is the number of subdirectories in that directory. I tried:

gsamaras@gwta3000 ~]$ hadoop fs -find /mydir/ -maxdepth 1 -type d -print| wc -l
find: Unexpected argument: -maxdepth
0

I know that the directory is not empty, thus 0 is not correct:

[gsamaras@gwta3000 ~]$ hadoop fs -du -s -h /mydir
737.5 G  /mydir

解决方案

The command to use is: hdfs dfs -ls -R /path/to/mydir/ | grep "^d" | wc -l

But this will also give you the error java.lang.OutOfMemoryError: Java heap space. In order to avoid the error, you need to increase the java heap space and run the same command as:

export HADOOP_CLIENT_OPTS="$HADOOP_CLIENT_OPTS -Xmx5g" and then

hdfs dfs -ls -R /path/to/mydir/ | grep "^d" | wc -l .....#For all sub-directories

OR

hdfs dfs -ls /path/to/mydir/ | grep "^d" | wc -l .....#For maxdepth=1

这篇关于目录中的子目录数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆