How to put files with spaces in names into HDFS?

I got this error when I tried to save a file with a space in its name into HDFS:

$ hdfs dfs -put -f "/home/u1/testa/test a" "/u1/testa/test\ a"
put: unexpected URISyntaxException

while the HDFS seems allow spaces in its file names: https://hadoop.apache.org/docs/r2.7.3/hadoop-project-dist/hadoop-common/filesystem/model.html .

How to achieve the effect of saving the files with spaces in its names into HDFS?

asked Mar 31 by anonymous

1 Answer

A tip to help you save a file with spaces in its name into HDFS: putting file from STDIN. One example is as follows:

date | hdfs dfs -put - "/path/file with space.txt"

For your example above, the command can be:

cat "/home/u1/testa/test a" | hdfs dfs -put -f - "/u1/testa/test\ a"

Then your file will be save into HDFS successfully with the space kept.

Note that if you would like to keep the mode of the file, you will need to set it explicitly using hdfs dsf -chmod ....

answered Mar 31 by zma (380 points)

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...