HDFS - Hadoop Distributed File System

56 / 58

Set Replication Factor

For setting the replication factor, we use below command

hadoop fs -setrep 2 file_name

Where 2 is the new replication factor which we want to set and file_name is the file whose replication we want to change.

If you want to wait till the process gets over, use -w and if you want to set the replication for entire directory please use an option -R on command line. For example, the following command will set the replication factor of 2 of all the files in a directory 'mydir' and it will wait for the completion:

hadoop fs -mkdir mydir 
hadoop fs -put wordcountscript.sh mydir
hadoop fs -setrep -R -w 2 mydir

Here is the output:

Replication 2 set: mydir/wordcountscript.sh
Waiting for mydir/wordcountscript.sh ... done


In the previous step, we have copied myfirstfile.txt to HDFS. Now set its replication factor to 2.

Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...