How to delete a folder in any Linux distribution

For those who are used to working with the Windows operating system, performing certain tasks in Linux can be a real problem. A clear example of this is when it comes to deleting a folder. If we use a desktop version of Linux, deleting a folder can be very simple. The problem is when you have to use the command line to carry out this action.

To help those of you who are just starting out in the world of Linux, today we would like to explain several options for deleting a folder in a simple and effective way.

Linux with desktop environment

As we have already mentioned, if the installed distribution has a desktop environment, the deletion of any folder is done in a similar way to what we do in Windows. That is to say, you would have to place the mouse over the folder to be deleted, right-click on it, and in the menu that appears, select the option Move to trash or Delete. With this, the folder and its contents will be moved to the bin, so that it can be recovered if necessary and as long as the bin is not emptied.

If the folder is very heavy, the system will ask if we want to permanently delete the folder and all its contents.

From the command line

When you don’t have any desktop environment, or you want to delete a directory that requires certain privileges to be deleted, the option to use is the command line.

In this case, there are several ways to carry out this action, depending on whether the folder is empty or not.

Empty folder

rmdir folder_name

Folder with files and other folders

rmdir -r folder_name

You also have the option of deleting everything inside the directory, but the directory still exists. In this case, the commands to use would be the following:

Delete all the files in the folder

rm /path/from/folder/*

Delete also the subfolders

rm -r /path/from/folder/*

As you can see, it is not at all complicated to do this kind of deletion on Linux systems. The only thing is to know the commands that exist for it.

Scroll to Top