Skip to content
Linuxinfra.com
Menu
  • Home
  • Linux Security
  • Linux Administration
    • Linux History
    • Why Linux is Better?
    • What Are Linux Distributions?
    • Linux kernel and shell
    • Processes in Linux/Unix
    • Linux Basic Commands
  • Cyber Security
    • PCI DSS
      • Module 1: Introduction to PCI DSS
      • Module 2: PCI DSS Requirements Overview
      • Module 3: Scope of PCI DSS Compliance
      • Module 4: Risk Management and Vulnerability Assessments
      • Module 5: Implementing and Maintaining PCI DSS
      • Module 6: Compliance Validation and Reporting
      • Module 7: Best Practices and Case Studies for PCI DSS
      • Module 8: Updates and Future of PCI DSS
Menu
rmdir command

Understanding the rmdir Command in Linux

Posted on August 25, 2024

The rmdir command in Linux is used to remove (delete) empty directories. Unlike the rm command, which can delete files and directories, rmdir is specifically designed to remove only empty directories. It’s a straightforward and safe tool for cleaning up unused directories in your filesystem.

In the above, ls command given the current list of directories and files. Once we executed rmdir dir01, this has deleted the empty folder and in the next ls command dir01 directory is not showing becasue this has already deleted.

If the directory is not empty, rmdir will not delete it and will return an error.


rmdir Command Options (Switches)

Although rmdir is a simple command, it does have a few options that can make it more versatile.

Description: The -p option allows you to remove a directory and its parent directories if they become empty after the removal. This is particularly useful when you want to clean up a nested directory structure.

-p (Remove Parent Directories)

--verbose (Verbose Output)

  • Description: The --verbose option provides detailed output of what rmdir is doing, which is helpful for tracking the deletion process, especially when working with multiple directories.

Limitations of rmdir

While rmdir is useful for removing empty directories, it’s important to note that it cannot remove directories that contain files or other directories. If you need to remove non-empty directories, you’ll need to use the rm command with the -r (recursive) option:

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

cloud infrastructure community support customizability data protection developer tools free software hardware support lightweight Linux Linux applications Linux command line Linux Community Linux community support Linux development Linux Distributions Linux for old hardware Linux for servers Linux graphical interface Linux installation Linux Kernel Linux package manager Linux performance Linux rolling release linux security Linux security tools Linux server Linux software Linux support Linux terminal Linux updates multitasking multiuser networking no bloatware open-source performance privacy privacy control programming scalability secure OS security software repository stability system resources

  • January 2025
  • November 2024
  • September 2024
  • August 2024
  • March 2024
  • January 2024
  • December 2023
©2025 Linuxinfra.com | Design: Newspaperly WordPress Theme