In my last post I talked about the 3 main ways of creating files from the command line. Today I will look at how to remove a file. Generally, to remove anything you would use the following command.
This is a very simple command, although by using some flags we can make it both safer and easier to use. -I gives a prompt before removing three or more files or when removing recursively, -v (or –verbose) prints everything that has been removed. You can also use the sudo command to remove a file from a folder where you do not have permissions to write.
sudo rm -Iv myfile.text
Using the -I command forces you to give another input to remove more than 3 files, this can be very useful in making sure that you do not delete a file by mistake.
The rm command can also remove folders and all of its contents. To do this you simple need to name the folder and use the -r flag.
rm -rIv myfoler
You can also specify a file or folder location in the form of /path/to/location in order to remove from another location.
Hopefully this helps someone, I know how long learning the command line commands can take, and often you use commands for a long time before you understand how they work.