如何更新HDFS中的文件 [英] How to update a file in HDFS
问题描述
我知道HDFS只能写入一次并且可以读取多次.
假设我要更新HDFS中的文件,有什么办法吗?
I know that HDFS is write once and read many times.
Suppose if i want to update a file in HDFS is there any way to do it ?
先谢谢您!
推荐答案
选项1:
如果您只想添加到现有文件中
If you just want to append to an existing file
-
echo "<Text to append>" | hdfs dfs -appendToFile - /user/hduser/myfile.txt
或
hdfs dfs -appendToFile - /user/hduser/myfile.txt
,然后在终端上键入文本.输入完毕后,点击"Ctrl + D"
hdfs dfs -appendToFile - /user/hduser/myfile.txt
and then type the text on the terminal. Once you are done typing then hit 'Ctrl+D'
选项2:
将原始文件从HDFS获取到本地文件系统,对其进行修改,然后再将其放回HDFS.
Get the original file from HDFS to the local filesystem, modify it and then put it back on HDFS.
-
hdfs dfs -get /user/hduser/myfile.txt
vi myfile.txt
#或使用其他任何工具并对其进行修改
vi myfile.txt
#or use any other tool and modify it
hdfs dfs -put -f myfile.txt /user/hduser/myfile.txt
这篇关于如何更新HDFS中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!