Rename directory in hdfs

前端 未结 3 1791
自闭症患者
自闭症患者 2021-02-19 04:20

I need to rename a directory in hdfs. What is the command for that ?

hadoop fs -mv   

The above command moves the src f

3条回答
  •  旧时难觅i
    2021-02-19 05:01

    I think you are missing the point about mv command(linux/hdfs).

    When the destination already exists, if it's a file, an error message mv: 'dest': File exists.
    In case of directory, the source will go inside it. So the command is working acceptably, just try it with a non-existent dest.

    Now to resolve this, you can make use of hadoop's test command along with short circuit OR of linux.

    hadoop fs -test -e dest || hadoop fs -mv src dest 
    

    If the directory doesn't exist, invoke mv. You can even go further with the following:

    hadoop fs -rmr dest  
    hadoop fs -mv src dest  
    

    This one deletes the dest dir first, then performs the move action. if this is not your intention, use the previous solution.

提交回复
热议问题