问题
I need to rename a directory in hdfs. What is the command for that ?
hadoop fs -mv <src> <dest>
The above command moves the src folder into dest folder. Instead of, I want the src
folder to be renamed as dest
.
回答1:
Rename is not in hadoop, but you can move, hadoop fs -mv oldname newname
回答2:
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.
回答3:
You can rename the folder in HDFS environment by using mv command
hadoop fs -mv 'Old folder name with path' ' new folder name with path'
Example: I have folder in HDFS at location /test/abc
and I want to rename it to PQR
hadoop fs -mv '/test/abc' '/test/PQR';
Results:
来源:https://stackoverflow.com/questions/27286946/rename-directory-in-hdfs