HDFS Delete Directories: hadoop fs -rmdir
![](https://ashwin.cloud/wp-content/uploads/2023/08/featured_hadoop_fs_rmdir.webp)
The hadoop fs -rmdir
command is used to delete a directory in Hadoop Distributed File System (HDFS).
In this blog post, we will explore the hadoop fs -rmdir
command’s usage and its most commonly used flags with examples to help you become proficient in deleting directories in HDFS.
Another command, hadoop fs -rm
, provides an extended range of capabilities and serves as a versatile option for deleting both files and directories. For a comprehensive understanding of the hadoop fs -rm
command, you can refer to the content covered in this blog post.
Command Syntax:
hadoop fs -rmdir [options] <path>
path
: The path to the directory to be deleted.options
: The following options are available:-f
: Force the deletion, even if the directory is not empty.- Example:
hadoop fs -rmdir -f /user/hadoop/mydir
- Example:
Remove Empty Directory
This basic usage of the command removes the specified empty directory from HDFS.
hadoop fs -rmdir <path>
Example:
In this example, the command removes the empty directory named empty_dir
from the /user/hadoop/
directory in HDFS.
hadoop fs -rmdir /user/hadoop/empty_dir/
Forceful Removal (-f)
The -f
flag allows you to forcefully remove the directory, even if it’s not empty.
hadoop fs -rmdir -f <path>
Example:
By using the -f
flag, the command forcefully removes the directory non_empty_dir
even though it contains files.
hadoop fs -rmdir -f /user/hadoop/non_empty_dir/
Leave a Reply