2 Ways to Delete a Directory in Linux

2 Ways to Delete a Directory in Linux

Sometimes, we try to remove a folder or directory from the file manager by moving it to the trash, but it does not work properly. In that case, you need to remove the directory with the terminal. Today, we will learn about how to delete a directory in Linux.

Table of Contents

There are two ways to delete a directory in Linux: removing it using the file manager, using the “rmdir” command, or using the “rm” command. You can follow all the steps carefully to successfully remove any un-removable directory without wasting your time. Now, we can jump to the remove directory section. All methods are easy and work perfectly in any Linux operating system.

Delete a Directory in Linux

Now, follow these three easy methods in any Linux distribution to remove any directory from Linux.

Remove Linux Directory using File Manager

This is the normal delete method that most people know about. To delete any file with this method, you can just right-click on the directory to show the menu. You can then select the “Move to Trash” option. Click on this option to move the file to the trash. In the file manager, you can show the trash option. Open this and remove the folder by clicking on the “Empty Trash” option. This process takes two steps.

Remove Directory with Terminal

This is the second and most popular method to remove the directory without visiting and accessing the file manager. This method is mostly used in the core web server through an SSH client. There are two ways to remove the folder with the terminal. The first is the “rmdir” command.

rmdir command

rmdir command mostly used for removing an empty directory. It is not able to remove any folder when multiple files are available. When we try to remove any non-empty folders, we can see the “rmdir directory is non-empty” error message. From this image, you can see that this is not so helpful. Then, most of the time, we can avoid it. Now, we can always use the “rm” command to remove any directory. For using this, you can follow the given command:

					rm -r Folder_Directory

remove directory with rm command

Here, you can notice that “-r” or “-R” is included in the command line. This sign is used to remove the directory fully. In some cases, the “rm” command is not able to remove the directory. Then, “-r” or “-R” is most important for removing the directory.

directory lock icon

Sometimes, you can get this type of error message in your file manager. The given directory’s icon shows a lock icon. In this case, you can open the terminal on this directory and move to the root user with the “sudo su” command. Then, put the “rm -r” directory name to remove the directory.

Thanks for visiting my blog. If you like this post, then don’t forget to subscribe to my blog to get all my new blog posts’ notifications.