MIAP Digital Literacy Command Line Guide

Learn about BASH commands!

View on GitHub

The rm Command

Summary

The rm command removes files you no longer need. It removes the entries for a specified file, group of files, or certain select files from a list within a directory. User confirmation, read permission, and write permission are not required before a file is removed when you use the rm command. However, you must have write permission for the directory containing the file.

Basic command structure

For all descriptions below, the dollar sign indicates that BASH command prompt.

$ rm [option] [file name]

Possible Flags

-i

The -i flag will ask before deleting each file. Some people will have rm aliased to do this automatically (type “alias” to check). Consider using rm -I instead, which will only ask once and only if you are trying to delete three or more files.

-r

The -r flag will recursively delete a directory and all its contents (normally rm will not delete directories, while rmdir will only delete empty directories).

-f

The -f flag will forcibly delete files without asking; this is mostly useful if you have rm aliased to ``rm -i’’ but want to delete lots of files without confirming each one.

Output

The rm command has many different kinds of outputs as described below:

A standard rm command, without the -v flag, will generally only give outputs if there is an error.

Examples

Go back to the main list of commands