+5 votes
177 views
in Setting by (242k points)
reopened
How to delete a directory in Linux easily

1 Answer

+3 votes
by (1.6m points)
edited
 
Best answer

Delete a directory in Linux: file manager
Delete directory on Linux: terminal

How to delete a directory in Linux easily

If you want to delete all the files in a folder, the most practical thing is to delete the entire directory to avoid the tedious work of having to select each file individually, as this saves a lot of time. There are different solutions to delete a directory in Linux quickly and easily..

Index
  1. Delete a directory in Linux: file manager
  2. Delete directory on Linux: terminal

Delete a directory in Linux: file manager

The easiest way to delete directories in Linux is through the file manager:

  1. In the file manager, navigate to the directory you want to delete.
  2. Right-click on the directory, then click ? Move to Trash? in the drop-down menu .
Done

There are numerous Linux distributions that have different graphical interfaces, but their structure is usually similar. The presented procedure should work on Ubuntu, Fedora, and even Debian.

image
With the menu option? Move to Trash ?, you can delete a directory in Linux.

It is possible that certain directories can be removed only with administrator rights . Depending on the file manager you use, it asks you (similar to Windows) if you want to delete the directory with these rights. If the file manager doesn't ask, you have to start it from the terminal with? Sudo? or? su ?. With this step, you automatically get administrator rights to the graphical file manager..

advice

If you are not sure what the file manager is called, you can find the name in? Help ?,? About? or ??? in the file manager menu.

Delete directory on Linux: terminal

For the terminal there are several Linux commands that have different functions. In this way, in addition to files, you can delete directories in Linux using commands..

  1. Open the file manager and navigate to the directory you want to delete. An alternative is to open the terminal directly and access the folder with the command? cd / path / to / directory? which contains the directory.
  2. Click on the window with the right mouse button and the menu options will open. Here, select? Open in terminal? .
image
With a right click of the mouse, in the file manager you can directly open the terminal with the pre-selected path to the directory.
  1. Enter the command? Rm? R? (short for remove ) and the directory name to remove the entire folder and its contents.
  rm -r archivos  
Note

Deleting a directory in Linux also removes all files and subdirectories contained within it. To avoid getting an error message, add? -R? to command . In this way, you can delete the directory and all the contained files recursively.

image
With a right click of the mouse, in the file manager you can directly open the terminal with the pre-selected path to the directory.

In the same way as with the file manager, certain directories can only be deleted with administrator rights on the terminal . In this case, it changes the command line to user? Root? introducing? su? and your root password . Another option without having to change user is to type the following command to delete a directory in Linux with administrator rights:

  sudo rm -r nombre del directorio  

...