如何在HDFS中递归列出子目录?

7
我有一组在HDFS中递归创建的目录,如何列出所有目录?对于普通的Unix文件系统,我可以使用以下命令来完成:
find /path/ -type d -print

但是我想要类似的东西来处理HDFS。


有用的问题,但我想知道目录的大小,以更好地复制du功能。 - ChuckCottrill
3个回答

8

To list directory contents recursively hadoop dfs -lsr /dirname command can be used.

To filter only directories , you can grep "drwx" (since owner has rwx permission on directories) in output of above command.

Hence whole command will look like as below.

$hadoop dfs -lsr /sqoopO7 | grep drwx 


8

@Shubhangi Pardeshi提供的答案是正确的,但对于最新的Hadoop版本,该命令已被弃用。因此,可以使用下面的最新命令。

hdfs dfs -ls -R /user | grep drwx

0
以下的方法应该更加健壮,只获取目录,因为它对权限的依赖较少。
hdfs dfs -ls -R /folder | grep "^d"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接