Last Updated on May 22, 2022
The rm command removes files or directories. The command needs to be used with extreme caution. There’s no undelete command or wastebasket when removing files from the shell.
When you delete a file or directory with rm, you cannot get it back. Make sure you perform regular backups on all important data and test your backups.
We can remove files from specific locations. For example:
$ rm path/to/file path/to/another/file
We can also recursively remove a directory and all its subdirectories with the command:
$ rm -r path/to/directory
The next command forcibly removes a directory, without prompting for confirmation or showing error messages. Use this command with extreme caution.
$ rm -rf path/to/directory
You can also interactively remove multiple files, with a prompt before every removal:
$ rm -i file(s)
And there’s a verbose mode, printing a message for each removed file:
$ rm -v path/to/directory/*
Again wildcards can be used with the rm command. But we strongly recommend before running rm you sit on your hands and think what you are doing. And make sure you backup!
All articles in this series: