Creating and deleting directories is a key part of any operating system. This is no different for any OS that is based on Linux. There exist a few different ways using which a directory can be deleted in a Linux system. This article will act as your guide and teach you how you can perform deletion on any directory in Linux using various methods.
How to Delete a Directory in Linux?
There are two major methods in the Linux operating system through which a directory can be deleted.
Let’s learn more about these two different methods of deletion.
Method 1: Using the Terminal to Delete a Directory
The first method of removing/deleting any directory from the system is to use the “rm” keyword. This is the remove command used to remove any directories or files. In the case that the directory is not empty, the “-r” command is added to recursively remove the sub-directories and the files inside it.
In our case, the following command will delete/remove the directory “Extracted” alongside its sub-directories:
$ rm -r /home/itslinuxfoss/Desktop/Extracted
Here “rm” is the remove keyword, and the “-r” will make sure that everything inside the directory is removed as well. Its working is shown below:
The directory is removed successfully. That’s it! You have learned to delete a directory via GUI and CLI in Linux.
Method 2: Using GUI to Delete a Directory
The second method is rather simple since it involves the use of the graphical user interface. Firstly, you need to navigate to the location where the directory resides. In our case, we want to delete the directory as shown below:
The next step is to simply right-click this directory and click on the “Move to Trash” option. This option will delete the directory even if there are other files or sub-directories inside it. Check out the snippet below:
There are two major methods through which any directory present inside a Linux operating system can be deleted. The first method is the standard GUI method. In this, you simply right-click on the directory that you want to delete and select the Trash option. The other method makes use of the Linux terminal and uses the “rm” command with the “-r” flag to delete directories that are not empty. This article has provided you with the knowledge on how to delete any directory in Linux using two distinct methods.
TUTORIALS ON LINUX, PROGRAMMING & TECHNOLOGY