Is there any way we can overwrite existing files, while coping from HDFS
using:
hadoop fs -copyToLocal <HDFS PATH> <local path>
Is there any way we can overwrite existing files, while coping from HDFS
using:
hadoop fs -copyToLocal <HDFS PATH> <local path>
fs -copyFromLocal -f $LOCAL_MOUNT_SRC_PATH/yourfilename.txt your_hdfs_file-path
So -f
option does the trick for you.
It also works for -copyToLocal
as well.
You can first delete, then write.
hadoop fs -rmr <path>
removes everything under given path in hdfs including the path itself
rm -rf <path>
removes in local file system.
Make sure that there is no other file in the directory.
Force option is not there for either of the commands (get
/copytolocal
).
Below are three options:
Remove the file on localmachine with rm command and use copyToLocal/get
.
Rename your local file to new name so that you can have the file with same name as on cluster. use mv command for that and use get/copyTolocal
command.
Rename the file there on the cluster itself and use copytolocal
hadoop fs -mv [oldpath] [newpath]
hadoop fs -copytolocal [newpath] .
-f
option did the trick
example:
bin>hdfs dfs -put -f D:\DEV\hadoopsampledata\mydata.json /input
You can try with distcp with -update . Main advantage is it will be update the target only when there is change in the file.
hadoop distcp -update file://source hdfs://namenode/target
hadoop distcp -update file:///home/hduser/pigSample/labfiles/SampleData/books.csv hdfs://10.184.37.158:9000/yesB
You could try this :
bin/hadoop fs -rm /path_of_the_file | grep "0" | bin/hadoop fs -put ~/input_path /output_path