Home Softwares/Apps How to delete a directory in Linux?

How to delete a directory in Linux?

delete a directory in Linux

You have come to the right place to learn how to delete a directory in Linux. In this detailed guide, we will go over the step-by-step instructions.

In order to remove or delete directories in Linux, you will have to use rmdir and rm commands for removing them.

There are two types of directories in Linux. Directories may be empty or have some content in them. “rmdir” is a command-line feature for deleting empty directories. The “Rm” command is used to delete directories and their contents. Below are some examples of how to delete a directory in Linux.

  1. To delete an empty directory: Use the “rm -d” or “rmdir” command. This command follows the name of the directory you want to delete.
  2. To delete a directory that contains some files: Use the “rm” command. with a recursive option. “-r” indicates the recursive option.
  3. For files that are write-protected: Sometimes directory contents are “write-protected”. Write protection is the process of stopping the transfer or deletion of valuable data. If the contents of the directory are ” Write Protected”, the user will be asked again to confirm the removal process.
  4. If you do not want to see a prompt window pop up during the direct removal process: use the “rm” command with -r and -f options.
  5. To save time and delete multiple directories at once: Use the “rm” command with -r. Separate different directory names by space.

Be very careful when deleting files and directories. Once directories are deleted, they are difficult to retrieve. So, think through and delete directories carefully.

Read More: Facing Command ‘x86_64-Linux-gnu-GCC’ failed with exit status 1 error.