How can I list subdirectories recursively for HDFS? How can I list subdirectories recursively for HDFS? hadoop hadoop

How can I list subdirectories recursively for HDFS?


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


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 


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"