0
0
HadoopHow-ToBeginner ยท 3 min read

How to Create Directory in HDFS in Hadoop Quickly

To create a directory in HDFS, use the hdfs dfs -mkdir /path/to/directory command. This creates the specified directory in the Hadoop Distributed File System.
๐Ÿ“

Syntax

The basic syntax to create a directory in HDFS is:

  • hdfs dfs: The Hadoop file system shell command.
  • -mkdir: The option to create a new directory.
  • /path/to/directory: The full path of the directory you want to create in HDFS.
bash
hdfs dfs -mkdir /user/yourusername/newdirectory
๐Ÿ’ป

Example

This example shows how to create a directory named data inside the /user/hadoop folder in HDFS.

bash
hdfs dfs -mkdir /user/hadoop/data
โš ๏ธ

Common Pitfalls

Common mistakes when creating directories in HDFS include:

  • Trying to create a directory without proper permissions, which causes a permission denied error.
  • Using a relative path instead of the full HDFS path.
  • Not having the Hadoop services running, so the command fails.

Always ensure you have the right permissions and use the full HDFS path.

bash
hdfs dfs -mkdir data
# Wrong: This uses a relative path and will fail

hdfs dfs -mkdir /user/hadoop/data
# Correct: Uses full HDFS path
๐Ÿ“Š

Quick Reference

CommandDescription
hdfs dfs -mkdir /path/to/dirCreate a new directory in HDFS
hdfs dfs -ls /path/to/dirList contents of a directory
hdfs dfs -rm -r /path/to/dirRemove a directory and its contents
โœ…

Key Takeaways

Use the full HDFS path with the -mkdir command to create directories.
Ensure you have the necessary permissions to create directories in HDFS.
Always check that Hadoop services are running before executing commands.
Use hdfs dfs commands to interact with HDFS from the shell.