How to update a file in HDFS

后端 未结 2 1405
执笔经年
执笔经年 2021-01-04 14:23

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 ?

Thankyou in advance !

2条回答
  •  执笔经年
    2021-01-04 14:45

    Option1:

    If you just want to append to an existing file

    1. echo "" | hdfs dfs -appendToFile - /user/hduser/myfile.txt OR

    2. hdfs dfs -appendToFile - /user/hduser/myfile.txt and then type the text on the terminal. Once you are done typing then hit 'Ctrl+D'

    Option2:

    Get the original file from HDFS to the local filesystem, modify it and then put it back on HDFS.

    1. hdfs dfs -get /user/hduser/myfile.txt

    2. vi myfile.txt #or use any other tool and modify it

    3. hdfs dfs -put -f myfile.txt /user/hduser/myfile.txt

提交回复
热议问题