The rm (remove) command enables you to delete files and directories. Be warned: rm is a dangerous command. It doesn't really offer you a second chance. When files are deleted, they're gone. You can use rm -i as in the last example below. The -i option makes the rm command interactive, prompting the user for confirmation before each removal. That at least gives you a second chance to think about it, but as soon as you agree, once again, the file is gone.
Some people like to create an alias (see Chapter 14, ''Working with the System'') that makes the rm command act like rm -i. But you should be careful about using this: It will lull you into a false sense of security, and when you're working on a system where this change has not been made, you may regret it.
Doug Gwyn, a well-known Internet personality, once said, "Unix was never designed to keep people from doing stupid things because that policy would also keep them from doing clever things.'' You can, of course, use rm to delete every file on your system as simply as this: rm -rf /. That command means "remove (rm) recursively (-r) and force (-f) the root directory of the system (/).'' So it deletes everything on the system. (You need to be logged in as the root user, who has the privileges to do this, but you get the idea.) Some better examples of using the rm command in daily use are:
■ rm * — Removes all (nonhidden) files in the current directory. The rm command will not remove directories unless you also specify the -r (recursive) option.
■ rm-rf doomed — Removes the directory doomed and everything in it.
■ rm -i a* — Removes all files with names beginning with a in the current directory, asking for confirmation each time.
Was this article helpful?