Managing Directories in HDFS
Creating Directories in HDFS
To create a new directory in HDFS, you can use the hdfs dfs -mkdir
command. For example, to create a directory named "mydata" in the root directory of HDFS, you can run the following command:
hdfs dfs -mkdir /mydata
You can also create multiple directories at once by specifying multiple paths:
hdfs dfs -mkdir /mydata /anotherdir /someotherdir
Listing Directory Contents
To list the contents of a directory in HDFS, you can use the hdfs dfs -ls
command. For example, to list the contents of the root directory, you can run:
hdfs dfs -ls /
This will display a list of files and directories in the root directory, along with their size, replication factor, and modification time.
Deleting Directories
To delete a directory in HDFS, you can use the hdfs dfs -rm -r
command. For example, to delete the "mydata" directory and its contents, you can run:
hdfs dfs -rm -r /mydata
Note that the -r
option is used to recursively delete the directory and its contents.
Renaming Directories
To rename a directory in HDFS, you can use the hdfs dfs -mv
command. For example, to rename the "mydata" directory to "newdata", you can run:
hdfs dfs -mv /mydata /newdata
This will move the "mydata" directory to "newdata" within the same parent directory.
Checking Directory Permissions
HDFS supports file and directory permissions, which can be managed using the hdfs dfs -chmod
command. To check the permissions of a directory, you can use the hdfs dfs -ls -l
command, which will display the permissions, owner, and group for each file and directory.