The rm command can be used to delete files and directories in Linux.
To delete a file or folder, one would simply use rm in the following manner:
Depending on permissions, you may need to write sudo in front of rm.
sudo rm /var/www/mysite/index.html
You can also navigate to the directory before deleting the file using the cd command.
cd /var/www/mysite sudo rm /var/www/mysite/index.html
To move back to your home directory, do something like this:
The command is useful when you are writing scripts, and when managing a computer or server remotely. Mostly since you typically do not have access to a GUI in those cases. Other than this, it is mostly personal preference. Some users find it faster to use the terminal, while others find it difficult to remember commands. Etc.
Using the terminal vs your file manager
Alternatively you may also delete files and folders with your favorite file manager. Nemo makes it easy, as it has the option to "Open as Root" when right clicking on a directory. But you could also launch Nautilus as root.
Many Linux users prefer to use the terminal, and some are (irrationally) against using a GUI. However, any modern OS should be expected to offer GUIs, both for productivity, and to make things easier for their users. With the terminal, users often have to learn, and memorize complex commands – something we can not expect users to do.
Nautilus may be launched with the following command:
sudo -i nautilus
|Option||What is this?|
|-v or --verbose||Show what is being done. I.e. Prints the filename, before removing the file.|
|-f or --force||Ignore nonexistent files and doesn't prompt the user.|
|-i||Prompt the user before removing each file.|
|-I||Prompt once whether to proceed with the command, if more than three files are named or if a recursive removal is requested.|
|--interactive=once||Prompt once whether to proceed with the command, if more than three files are named or if a recursive removal is requested.|
|--interactive=never||Show no Prompts to the user at all.|
|--interactive=always||Prompt for every file being removed.|
|--interactive||Equivalent to --interactive=always|