Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HDFS: How do you list files recursively?

Tags:

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.

like image 529
wsb3383 Avatar asked Jun 08 '12 00:06

wsb3383


People also ask

How do you list the files in HDFS directory?

Use the hdfs dfs -ls command to list files in Hadoop archives. Run the hdfs dfs -ls command by specifying the archive directory location.

How do I list all files in HDFS and size?

You can use hadoop fs -ls command to list files in the current directory as well as their details. The 5th column in the command output contains file size in bytes. The size of file sou is 45956 bytes.

What command is used to list the files in a folder in Hadoop?

The ls command in Hadoop shows the list of files/contents in a specified directory, i.e., path. On adding “R” before /path, the output will show details of the content, such as names, size, owner, and so on for each file specified in the given directory.

How do I list files in hive?

To list out the databases in Hive warehouse, enter the command 'show databases'. The database creates in a default location of the Hive warehouse. In Cloudera, Hive database store in a /user/hive/warehouse. Copy the input data to HDFS from local by using the copy From Local command.


2 Answers

You can look at the source for org.apache.hadoop.fs.FsShell.ls(FileStatus, FileSystem, boolean, boolean) for your version of hadoop - this is what is called when you perform a hadoop fs -lsr path from the command line

  • 0.20.2 - line 593
  • 1.0.2 - line 590
like image 183
Chris White Avatar answered Oct 13 '22 12:10

Chris White


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.

like image 27
Ramineni Ravi Teja Avatar answered Oct 13 '22 11:10

Ramineni Ravi Teja