How to delete a folder in Linux through the terminal console
Linux is a operating systempowerful y versatile which offers users full control over their files and directories. One of the most common tasks that Linux users must perform is delete folders that they no longer need. Although this can be done through the graphical user interface, many users prefer to use the command terminal for a greater efficiency And control.
In this article, we will guide you through the process of delete a folder in Linux using the command terminal. You will learn the necessary commands and precautions you should take to avoid accidental deletion of important files. Let us begin!
Open the command terminal
The first step to delete a folder in Linux is to open the command terminal. You can do this using the keyboard shortcut Ctrl + Alt + T or by searching for "Terminal" in the applications menu of your Linux distribution.
Navigate to folder location
Once you have opened the terminal, you must surf to the location of the folder you want to delete. You can do this using the command cd
followed by the folder path. For example, if the folder you want to delete is located in /home/usuario/documentos
,you must write:
cd /home/usuario/documentos
Check the contents of the folder
Before deleting the folder, it is a good practice verify its content to make sure it doesn't contain important files that you might need in the future. You can do this using the command ls
:
ls nombre_de_la_carpeta
This will display a list of all the files and subfolders within the folder you want to delete.
Delete folder
Once you have verified the contents of the folder and are sure you want to delete it, you can use the command rm
with the option -r
(recursive) followed by folder name:
rm -r nombre_de_la_carpeta
This command will delete the folder and all its contents permanently. permanent bases, so you should use it with caution.
Confirm deletion of the folder
After running the command rm -r
, the terminal will ask you to confirms the folder deletion. You can do this by writing y
(yes) and pressing Enter. If you change your mind and want to cancel the deletion, you can write n
(no) and press Enter.
Verify that the folder has been deleted
For verify that the folder has been successfully deleted, you can use the command again ls
. If the folder no longer appears in the list, it means that it has been successfully deleted.
It is important to note that deleting a folder through the command terminal is irreversible, so you need to make sure that you really want to delete the folder and its contents before you run the command rm -r
.
Additionally, if the folder you want to delete requires superuser permissions, you must use the command sudo
before command rm -r
:
sudo rm -r nombre_de_la_carpeta
This will ask you to enter your superuser password before proceeding with deleting the folder.
In case you want to delete an empty folder, you can use the command rmdir
instead of rm -r
:
rmdir nombre_de_la_carpeta
This command only works with empty folders and will not delete folders that contain files or subfolders.
Learning to delete folders in Linux through the command terminal is a essential skill for any user of this operating system. With the commands and tips provided in this article, you will be able to delete folders efficiently and safely, keeping your system organized and free of unnecessary files.
Always remember verify content from a folder before deleting it and using the command rm -r
with caution, as deleting files through the terminal is permanent and cannot be undone. Now you're ready to start deleting folders in Linux like a real pro!