Removes (unlinks) files or directories.
{ rm | delete } [ -f ] [ -r ] [ -R ] [ -i ] [ -e ] File ...
The rm command removes the entries for the specified File parameter from a directory. If an entry is the last link to a file, the file is then deleted. You do not need read or write permission for the file you want to remove. However, you must have write permission for the directory containing the file.
If either of the files . (dot) or .. (dot, dot) are specified as the base name portion of the File parameter, the rm command writes a diagnostic message to standard error and does nothing more with such parameters.
The rm command writes a prompt to standard error and reads a line from standard input if the -f flag is not specified, and either the File parameter does not have write permission and the standard input is a workstation, or the -i flag is specified. If the response is not affirmative, the rm command does nothing more with the current file and proceeds to the next file.
The files owned by other users cannot be removed if the sticky bit of the directory is set and the directory is not owned by the user.
Note: The rm command supports the -- (dash, dash) parameter as a delimiter that indicates the end of the flags.
This command returns the following exit values:
0 | If the -f flag was not specified, all the named directory entries were removed; otherwise, all the existing named directory entries were removed. |
>0 | An error occurred. |
rm myfileIf there is another link to this file, then the file remains under that name, but the name myfile is removed. If myfile is the only link, the file itself is deleted.
rm -f coreNo confirmation prompt is issued before the rm -f command attempts to remove the file named core. However, an error message displays if the core file is write-protected and you are not the owner of the file or you do not have root authority. No error message displays when the rm -f command attempts to remove nonexistent files.
rm -i mydir/*After each file name is displayed, enter y to delete the file, or press the Enter key to keep it.
rm -ir manualThis command recursively removes the contents of all subdirectories of the manual directory, prompting you regarding the removal of each file, and then removes the manual directory itself, for example:
You: rm -ir manual System: rm: Select files in directory manual? Enter y for yes. You: y System: rm: Select files in directory manual/draft1? Enter y for yes. You: y System: rm: Remove manual/draft1? You: y System: rm: Remove manual/draft1/chapter1? You: y System: rm: Remove manual/draft1/chapter2? You: y System: rm: Select files in directory manual/draft2? Enter y for yes. You: y System: rm: Remove manual/draft2? You: y System: rm: Remove manual? You: yHere, the rm command first asks if you want it to search the manual directory. Because the manual directory contains directories, the rm command next asks for permission to search manual/draft1 for files to delete, and then asks if you want it to delete the manual/draft1/chapter1 and manual/draft1/chapter2 files. The rm command next asks for permission to search the manual/draft2 directory. Then asks for permission to delete the manual/draft1, manual/draft2, and manual directories.
If you deny permission to remove a subdirectory (for example, manual/draft2), the rm command does not remove the manual directory. Instead, you see the message: rm: Directory manual not empty.
/usr/bin/rm | Contains the rm command. |
/usr/bin/delete | Contains the delete command. |
The unlink subroutine.
Directory Overview in AIX Version 4.3 System User's Guide: Operating System and Devices.
File and Directory Access Modes in AIX Version 4.3 System Management Guide: Operating System and Devices.
Linking Files and Directories in AIX Version 4.3 System User's Guide: Operating System and Devices.