1) Create a directory in HDFS
Now let us have a look at how to create directories
- By default hdfs is superuser of HDFS
hadoop fs -mkdir– to create directories
This command creates the directory in HDFS if it does not already exist
hadoop fs -mkdir <Path> – used to create directories
If the directory already exists in HDFS, then we will get an error message that the file already exists.
Below is a command you can use to create without failing
hadoop fs -mkdir -p <Path> Do not fail if the directory already exists
Here is the command we can use to create a high level directory in which we will create a low level directory
hadoop fs -mkdir -p /user/training/highlevel/lowlevel
The hdfs fs -rmdir command is used to remove a directory in Hadoop HDFS.
where <directory> is the name of the directory you want to remove.
It’s important to note that the directory must be empty before it can be removed. If you try to remove a directory that is not empty, you will receive an error message saying “rmdir: <directory>: Directory is not empty.” To remove a non-empty directory, you need to first remove all the files and subdirectories in it.