Support Questions

Find answers, ask questions, and share your expertise

hdfs has two folder with same names

avatar

I have two folders in hdfs with same name under the same directory. I want to get rid of one of them, but how do i do that?

1 ACCEPTED SOLUTION

avatar
Contributor

Often this happens as there is a "hidden" character at the end of the file or folder name. For example a line break (\n, \r, etc).

 

If you list the files you can get a clue that is the case as usually the output will look strange with an extra line or something there.

 

You can try running a few commands like the following to see if it matches a file:

hdfs dfs -ls $'/path/to/folder\r'
hdfs dfs -ls $'/path/to/folder\n'
hdfs dfs -ls $'/path/to/folder\r\n'

 

If any of those match, then you can delete the incorrect one with a similar command.

If you get no luck with that, then pipe the ls output into "od -c" and it will show the special characters

hdfs dfs -ls /path/to/folder | od -c

View solution in original post

3 REPLIES 3

avatar
Master Collaborator

Hi @clouderaskme 

Creating same folder name in same directory is not allowed. 

Test:

# sudo -u hdfs hdfs dfs -mkdir /folder1
# sudo -u hdfs hdfs dfs -mkdir /folder1/subfolder1
# sudo -u hdfs hdfs dfs -mkdir /folder1/subfolder1
mkdir: `/folder1/subfolder1': File exists

 

So if you see two subfolder under folder1 with same name, it may due to contain special characters in name.

 

Can you log into the terminal and execute hdfs commands to check and also show us the output?

hdfs dfs -ls /folder1 | cat -A

 

Regards,

Will

avatar
Community Manager

@clouderaskme Has the reply helped resolve your issue? If so, please mark the appropriate reply as the solution, as it will make it easier for others to find the answer in the future.  If you are still experiencing the issue, can you provide the information @xxx has requested?



Regards,

Vidya Sargur,
Community Manager


Was your question answered? Make sure to mark the answer as the accepted solution.
If you find a reply useful, say thanks by clicking on the thumbs up button.
Learn more about the Cloudera Community:

avatar
Contributor

Often this happens as there is a "hidden" character at the end of the file or folder name. For example a line break (\n, \r, etc).

 

If you list the files you can get a clue that is the case as usually the output will look strange with an extra line or something there.

 

You can try running a few commands like the following to see if it matches a file:

hdfs dfs -ls $'/path/to/folder\r'
hdfs dfs -ls $'/path/to/folder\n'
hdfs dfs -ls $'/path/to/folder\r\n'

 

If any of those match, then you can delete the incorrect one with a similar command.

If you get no luck with that, then pipe the ls output into "od -c" and it will show the special characters

hdfs dfs -ls /path/to/folder | od -c