How to delete a folder in Linux

Delete a folder in Linux

There are people who think that in Linux everything is more difficult than in other operating systems such as Windows and macOS because for many things it is necessary to use the terminal. This could also be seen in another way: everything is easier because, in addition to allowing us to do things with a graphical interface as in Microsoft and Apple systems, it allows us to do what comes to us in wins from the terminal. Is not the same. One thing we can do in different ways is something as everyday as delete a folder in linux.

When looking for something like this on the Internet, it is because there is doubt, but sometimes what you want to know is how to do it using command lines or you are trying to do something that is blocked for some reason. The reasons can be many and varied, and here we are going to try to explain how to delete a folder in Linux, starting with the simplest, which is nothing more than doing it with the current file manager.

We can delete a folder in Linux just like in Windows

If there is no problem that is blocking it, we can delete a folder in Linux same as on Windows. To do this, just open the file manager, such as Nautilus, Dolphin or PCManFM, among others, right-click on the folder and choose "Move to trash", "Delete" or whatever appears. Depending on how we have it configured, we may have more than one option, one being to move it to the trash and the other to delete it entirely. If we choose the second, there is no going back.

Delete a folder in Dolphin

We can also try to do it in another way, which is by selecting the folder and pressing the Delete key (or Del, depending on the keyboard language). It is likely that we will come across a case where the key combination is different, and we will see what it is with the right click. In the screenshot above, we see that in Dolphin it is with the Delete key, and further down, the Delete key, the one that does not go through the trash can, is with Shift+Delete. By the way, the option to delete directly is not activated by default; You have to activate it from the options for security reasons.

From the terminal

Error when deleting a folder in Linux

It seems to me that some of those who come across this article from a web browser will have done so to find out how to delete a folder in Linux from the terminal. The command to delete is rm, but if we put in the terminal rm folder_name we will receive a message that will say “rm: cannot delete 'folder_name': It is a directory«. The problem is basically that a folder is not a file, and inside it can contain other folders and documents. Therefore, to remove them you have to do it recursively, that is, the first level (the folder itself) and all its sub-levels (its content).

But before we continue, we have to warn of something: if you delete a folder in linux from your terminal what we will do there is no going back. We have to be sure that we no longer want to see that folder or its contents, because that is what is going to happen. Having this clear, the command would remain (changing "name_of_the_folder" by the name of the folder).

rm -r nombre_de_la_carpeta

If we want to force the deletion, we can add the “f” (-rf) to the command. To the force delete It will ignore errors and warnings that may occur when trying to delete any file or folder, and will delete it directly.

As a curious fact for those who don't know it, there is a famous command that is often joked with in Linux, because the operating system allows it, but you never have to do it. The command is sudo rm -rf /, and would recursively delete everything on the system. And here "everything" means everything, literally. It would load folders such as /bin, /usr and everything necessary for the system to work, therefore, in addition to losing the information that we had not saved, we would also be left with a system that does not even serve as a paperweight. The -f option would be largely to blame, since it would hide any notices with which the operating system would let us know that something bad is going to happen.

Is the folder protected?

In Linux you can do anything, ask "a friend" who was doing tests and in a virtual machine (thank goodness...) he managed to load the /bin folder where all the executables of an operating system are, and without backtrack for having done it from the terminal. If we can't delete a folder, it's probably because is protected by the system or for any other reason, as it is from another user.

For example, if we want to do as "my friend" and load the /bin folder, which I am not recommending, but giving an example, all we have to do is do it from a user who has access to super-user privileges. , also known as root. If our user can do that, all we need to do is add "sudo" to the above command, which would look like:

sudo rm -r nombre_de_la_carpeta

As well we can try it with the file manager, if it can be opened with sudo, which would allow us to move through all our folders with elevated privileges. For example, Nautilus (Archives from GNOME) does allow it, and would let us delete protected folders (maybe not all) if we opened the terminal and typed "sudo nautilus" without the quotes. We will see two open windows, one with the terminal showing information and another that will be the file manager with its most basic interface (it does not usually respect customizations).

With Dolphin, when KDE allows it or where it allows it, the delete option should appear like any other, but before taking the step it will ask us for the administrator password. You can also do what we explain in this article to launch Dolphin as root.

Delete a folder with a Live USB

Another option to delete a folder in Linux is to do it from another Linux, specifically from a Live Session. There are some bugs that can be fixed this way, and one of them would be deleting a folder that was impossible to do from the native operating system (unlikely, but…). What we would have to do is create a Live USB, start from it, find the folder we want to delete and delete it.

As you can see, in Linux we have more options than in other operating systems and everything is possible, but don't do what it says in the highlighted text for your own good.

Leave a Comment

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



  1. Responsible for the data: AB Internet Networks 2008 SL
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.