rm
Files and directories
Usage
rm -rf [path]Deletes files for good — there is no trash can, and one stray space in rm -rf erases something you did not mean.
Common flags
| Flag | Meaning |
|---|---|
| -r | Descend into directories and delete what is inside |
| -f | Never prompt, and say nothing about files that are missing |
| -i | Ask before every single removal |
| -d | Remove an empty directory without -r |
| -v | Print each name as it goes |
| -I | GNU: ask once before removing more than three files |
| -P | macOS: overwrite the file before unlinking it |
Examples
rm -rf buildDeletes the build directory and everything under it.
rm -i *.logAsks about each log file first.
rm -- -weirdDeletes a file whose name starts with a dash.
Moving, deleting and finding. Some of these do not ask twice, which is why -i becomes a habit.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does rm do?
Deletes files for good — there is no trash can, and one stray space in rm -rf erases something you did not mean.
Q. How do I type it?
rm -rf [path] — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
7 are listed here; the full set is in man rm. This command sits under Files and directories.
Related commands
man page: man rm