Hdfs: How Do You List Files Recursively?
How Do You, Through Java, List All Files (Recursively) Under a Certain Path in Hdfs. I Went Through the Api and Noticed Filesystem. listFiles(Path, Boolean)...
How do you, through Java, list all files (recursively) under a certain path in HDFS. I went through the API and noticed FileSystem.listFiles(Path,boolean) but it looks like that method doesn't exist in my instance of FileSystem when I initialize it.
3 Answers
Use -R followed by ls command to list files/directorires recursively.
hadoop fs -ls -R Path/Of/File
Possible attributes for ls command are
-d : Directories are listed as plain files.
-h "Formats the sizes of files in a human-readable fashion rather than a number of bytes.
-R "Recursively list the contents of directories.
hadoop-user@hadoop-desk ~/hadoop
$ bin/hadoop fs -lsr /user/someone_else/myfiles
-rw-r--r-- 1 hadoop-user supergroup 0 2013-11-26 02:09 /user/someone_else/myfiles/file1.txt
-rw-r--r-- 1 hadoop-user supergroup 0 2013-11-26 02:09 /user/someone_else/myfiles/file2.txt
drwxr-xr-x - hadoop-user supergroup 0 2013-11-26 02:09 /user/someone_else/myfiles/subdir
-rw-r--r-- 1 hadoop-user supergroup 0 2013-11-26 02:09 /user/someone_else/myfiles/subdir/anotherFile.txt