How to delete a folder on Linux

remove linux

Deleting a folder in Linux can be done in different ways, both from the GUI and from the command line, and you can even use other commands to delete one of the directories you no longer want, Qu whether it is full or empty. In this simple tutorial, you will learn how to do it quickly. A tutorial for those new to GNU/Linux and some users who have been around a bit longer and may not know all the methods there are.

Of course, the most convenient and most accessible method is to use the desktop environment. Select the folder you want to delete, then right-click, and from the drop-down menu, press Move to Trash or Delete, depending on the environment. The directory and its contents will go to the Trash if it’s not too big, so you can go to the Trash and get its contents back if you want. If the directory contains too many gigabytes, it will ask you if you want to delete it permanently because it cannot be stored in the recycle bin and cannot be recovered.

On the other hand, you also have some directories that may require privileges to delete, and you won’t be able to do it from your file manager. So you will have to use a terminal for that. From the command console, you can do this in several ways; choosing one of these commands, the first deletes empty folders, and the second delete non-empty folders:

rmdir my folder

rmdir -r my folder

Now, if all you want is to delete all the contents of the folder but leave the folder intact, in that case, you can use these commands, the first to delete all files inside the folder and the second to delete also any subfolders that may exist:

rm /root/etc/myfolder/*

rm -r /root/etc/myfolder/*

Leave a Reply

Your email address will not be published.