14

I have set the replication factor for my file as follows:

hadoop fs -D dfs.replication=5 -copyFromLocal file.txt /user/xxxx

When a NameNode restarts, it makes sure under-replicated blocks are replicated. Hence the replication info for the file is stored (possibly in nameNode). How can I get that information?

Wyetro
  • 8,439
  • 9
  • 46
  • 64
brain storm
  • 30,124
  • 69
  • 225
  • 393

5 Answers5

19

Try to use command hadoop fs -stat %r /path/to/file, it should print the replication factor.

Aleksei Shestakov
  • 2,508
  • 2
  • 13
  • 14
15

You can run following command to get replication factor,

hadoop fs -ls /user/xxxx

The second column in the output signify replication factor for the file and for the folder it shows -, as shown in below pic.

enter image description here

Abhishek
  • 6,912
  • 14
  • 59
  • 85
2

Apart from Alexey Shestakov's answer, which works perfectly and does exactly what you ask, other ways, mostly found here, include:

hadoop dfs -ls /parent/path 

which shows the replication factors of all the /parent/path contents on the second column.

Through Java, you can get this information by using:

FileStatus.getReplication()

You can also see the replication factors of files by using:

hadoop fsck /filename -files -blocks -racks

Finally, from the web UI of the namenode, I believe that this information is also available (didn't check that).

vefthym
  • 7,422
  • 6
  • 32
  • 58
1

We can use following commands to check replication of the file.

hdfs dfs -ls  /user/cloudera/input.txt

or

hdfs dfs -stat %r /user/cloudera/input.txt
CertainPerformance
  • 356,069
  • 52
  • 309
  • 320
Viraj Wadate
  • 5,447
  • 1
  • 31
  • 29
1

In case if you need to check replication factor of a HDFS directory

hdfs fsck /tmp/data

shows the average replication factor of /tm/data/ HDFS folder enter image description here

Manju N
  • 886
  • 9
  • 14