How can I list subdirectories recursively for HDFS?
Asked Answered
R

3

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.

Repetend answered 25/6, 2015 at 17:14 Comment(1)
Useful question, but I would like to know the size of directories, to better replicate du functionality.Papal
A
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 
Acrophobia answered 25/6, 2015 at 17:35 Comment(0)
U
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
Unconstitutional answered 27/5, 2016 at 12:16 Comment(0)
R
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"
Reluctivity answered 28/4, 2021 at 15:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.