Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get hadoop put to create directories if they don't exist

Tags:

I have been using Cloudera's hadoop (0.20.2). With this version, if I put a file into the file system, but the directory structure did not exist, it automatically created the parent directories:

So for example, if I had no directories in hdfs and typed:

hadoop fs -put myfile.txt /some/non/existing/path/myfile.txt

It would create all of the directories: some, non, existing and path and put the file in there.

Now, with a newer offering of hadoop (2.2.0) this auto creation of directories is not happening. The same command above yields:

put: ` /some/non/existing/path/': No such file or directory

I have a workaround to just do hadoop fs -mkdir first, for every put, but this is not going to perform well.

Is this configurable? Any advice?

like image 387
owly Avatar asked May 07 '14 16:05

owly


People also ask

Is mkdir allowed in Hadoop?

Hadoop HDFS mkdir Command Description:This command creates the directory in HDFS if it does not already exist. Note: If the directory already exists in HDFS, then we will get an error message that file already exists. Use hadoop fs mkdir -p /path/directoryname, so not to fail even if directory exists.

What command is used to create a directory on hdfs?

1. mkdir: This is no different from the UNIX mkdir command and is used to create a directory on an HDFS environment. mention not to fail if the directory already exists.


2 Answers

Now you should use hadoop fs -mkdir -p <path>

like image 156
art-vybor Avatar answered Oct 17 '22 07:10

art-vybor


EDITORIAL NOTE: WARNING THIS ANSWER IS INDICATED TO BE INCORRECT


hadoop fs ... is deprecated instead use : hdfs dfs -mkdir ....

like image 36
aName Avatar answered Oct 17 '22 09:10

aName