rm

Remove a file (delete a link).

Format

   rm [options] file-list

Summary

The rm utility removes links to one or more files. It can be used to remove both hard links and symbolic links. When you remove the last hard link, you can no longer access the file, and the system releases the space the file occupies on the disk for use by another file (that is, the file is deleted).

To delete a file, you must have execute and write access permission to the parent directory of the file, but you do not need read or write access permission to the file itself.

Arguments

The file-list contains the list of files that rm deletes. Because you can remove a large number of files with a single command, use rm cautiously.

Options

-f force This option causes rm to remove files for which you do not have write access permission, without asking for your consent.
-i interactive This option causes rm to ask you before removing each file. If you use the -r option with this option, rm also asks you before removing each directory.
-r recursive This option causes rm to delete the contents of the specified directory, including all its subdirectories, and the directory itself. Use this option cautiously.

Notes

The section on the ln utility contains discussion about removing links.

Refer to the rmdir utility if you need to remove an empty directory.

Examples

The following command lines delete files, both in the working directory and in another directory.

z123456@turing:~$ rm memo
z123456@turing:~$ rm letter memo1 memo2
z123456@turing:~$ rm CS241/Assign1/prog1.o

The next example asks the user before removing each file in the working directory and its subdirectories. This command is useful for removing filenames that contain special characters, especially spaces, tabs, and newlines. (You should never create filenames using these characters on purpose, but it may happen accidentally.)

z123456@turing:~/CS241$ rm -ir .