Last Updated on May 22, 2022
rm
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!
Pages in this article:
Page 1 – cp
Page 2 – mv
Page 3 – rm
Page 4 – mkdir
All articles in this series:
Thanks. How many parts will this guide be?
We’re not certain of the final number of parts, but there’s plans for quite a few more. And we’re open to suggestions for additional areas that would help a beginner to Linux, or topics already covered where additional material would be welcome.