Wednesday, 23 March 2022

Hadoop: mkdir: Create parent directories along the path

‘-p’ option is used to create parent directories along the path, if not exists.

 

For example, in my case /user/cloudera folder has two directories demo1, demo2.

$hadoop fs -ls /user/cloudera
Found 2 items
drwxr-xr-x   - cloudera cloudera          0 2022-03-22 23:58 /user/cloudera/demo1
drwxr-xr-x   - cloudera cloudera          0 2022-03-23 03:01 /user/cloudera/demo2

 

Now I want to create the folder ‘dir1/dir2/dir3’ hierarchy in /user/cloudera.

 

If I try without -p option, I will end up in the error.

$hadoop fs -mkdir /user/cloudera/dir1/dir2/dir3
mkdir: `/user/cloudera/dir1/dir2/dir3': No such file or directory

Let me try with -p option.

$hadoop fs -mkdir -p /user/cloudera/dir1/dir2/dir3
$
$
$hadoop fs -ls -R /user/cloudera/dir1
drwxr-xr-x   - cloudera cloudera          0 2022-03-23 06:54 /user/cloudera/dir1/dir2
drwxr-xr-x   - cloudera cloudera          0 2022-03-23 06:54 /user/cloudera/dir1/dir2/dir3


Previous                                                 Next                                                 Home

No comments:

Post a Comment