Skip to content

Removing Directories with rmdir in Linux

Published: at 12:00 AMSuggest Changes

Table of Contents

Open Table of Contents

Introduction

The rmdir command is used to remove empty directories in Linux. It is a straightforward command for managing directory structures.

Basic Usage of rmdir

Syntax

The basic syntax of rmdir is:

rmdir [options] directory_name

Example

To remove an empty directory named “old_folder”:

rmdir old_folder

Common Use Cases

  • Removing Multiple Directories: You can remove multiple empty directories at once.
    rmdir dir1 dir2 dir3
    

Advanced rmdir Techniques

Using the -p Option

The -p option allows you to remove a directory and its parent directories if they are empty.

rmdir -p parent/child

Common Errors

  • Directory Not Empty: If the directory contains files or other directories, you will receive an error.
  • Permission Denied: Ensure you have the necessary permissions to remove the directory.

Conclusion

Understanding the rmdir command is essential for effective directory management in Linux.


Previous Post
Renaming Files and Directories in Linux
Next Post
Using scp in Linux Commands