Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hadoop in renaming files

Tags:

Is there a simple command for hadoop that can change the name of a file (in the HDFS) from its old name to a new name?

like image 567
stackoverflow_user1 Avatar asked Apr 08 '13 02:04

stackoverflow_user1


People also ask

How do I rename a file in Hadoop?

Use fs. rename() by passing source and destination paths to rename a file. Note that in the above example we also check if the file exists using fs. exists(path) method.

Can we rename a file in HDFS?

The answer is no. Renaming is the way to move files on HDFS: FileSystem. rename(). Actually, this is exactly what the HDFS shell command "-mv" does as well, you can check it in the source code.

Can we rename HDFS directory?

HDFS has the notion of Protected Directories, which are declared in the option fs. protected. directories. Any attempt to delete or rename such a directory or a parent thereof raises an AccessControlException.


2 Answers

Use the following :

hadoop fs -mv oldname newname  
like image 102
Sourav Gulati Avatar answered Oct 01 '22 07:10

Sourav Gulati


The above ones works pretty well. Also this version works all the time for me.

hdfs dfs -mv oldname.txt newname.txt 
like image 34
Junaid Khan Avatar answered Oct 01 '22 08:10

Junaid Khan