Deleting files in Linux couldn’t be easier. Whether you use the file manager or work directly in the terminal with the command “rm”, you can remove Linux files in just a few clicks. Keep reading to find out how to remove single files, multiple files, files of a certain type, or entire folders.
If you want to delete all files in a folder, it’s more practical to simply delete the entire directory. This saves you a lot of time, as you don’t need to select every individual file. This also lets you remove all subdirectories in the folder. Linux gives you many different solutions to quickly and easily remove a Linux directory.
Delete a Linux directory: file manager
The simplest way to delete a Linux directory is by using the file manager.
- In the file manager, go to the directory that you want to remove.
- Right-click on the directory and then click “Move to trash” in the menu that opens.
There are many different Linux distributions with different graphical interfaces, but they generally have a similar structure. The way shown below should work on Ubuntu, Fedora or Debian.
Sometimes, certain directories need administrator rights for you to delete them. Depending on the file manager you use, it might ask you if it should delete the directory using admin rights, just like Windows would. If the file manager doesn’t ask you this, you have to launch it with the commands “sudo” or “su” in Terminal. This will automatically grant you admin rights in the graphical file manager.
If you’re not sure what your file manager is called, you can find its name in the menu under “Help”, “About”, or “?”.
Delete a Linux directory: Terminal
There are several different Linux commands in Terminal, each with different functions. You can use these commands to delete individual files or entire Linux directories.
- Open your file manager and go to the directory you want to remove. You can also open Terminal directly and enter “cd /path/to/the/directory” to get to the folder that contains the directory.
- Right-click on the window and the menu will open. Select “Open in Terminal”.
- You can use the command “rm -r” (short for “remove”) followed by the name of the directory to delete the whole folder and all of its contents.
rm -r file
When you remove a Linux directory, you also remove all files and subdirectories in it. To avoid mistakes, the command needs to be extended with “-r”. This deletes the directory and all contained files recursively.
As is the case with the file manager, some directories can only be deleted through the Terminal if you have admin rights. In this case, change to a root user in the command line by typing “su” and your root password. If you don’t want to change user, you can also enter the following command to delete a Linux directory using admin rights:
sudo rm -r directoryname