7

I have a set of directories created in HDFS recursively. How can list all the directories ? For a normal unix file system I can do that using the below command

find /path/ -type d -print

But I want to get the similar thing for HDFS.

gsamaras
  • 71,951
  • 46
  • 188
  • 305
Koushik Chandra
  • 1,565
  • 12
  • 37
  • 73

3 Answers3

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 
Shubhangi
  • 2,229
  • 2
  • 14
  • 14
8

The answer given by @Shubhangi Pardeshi is correct but for latest hadoop version command has deprecated. So new latest command can be used as below

hdfs dfs -ls -R /user | grep drwx
Farooque
  • 3,616
  • 2
  • 29
  • 41
0

The following method should be more robust to only get directories because it depends less on the permissions.

hdfs dfs -ls -R /folder | grep "^d"
Benjamin Ziepert
  • 1,345
  • 1
  • 15
  • 19