Removes (unlinks) files or directories.
rm [ -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. If you do not have write permission for a file and the standard input is a terminal, you are prompted with the file name and ask to confirm that you want to delete the file. If you type a y (for yes), the file is deleted, type any other character and the file is not 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 the file is a symbolic link, the link is removed, but the file or directory that the symbolic link refers to remains. You do not need write permission to delete a symbolic link, if you have write permission in the directory.
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 myfile
If 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.
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: y
Here, 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. |
The ln command.
The unlink subroutine.
Directory Overview in AIX 5L Version 5.2 System User's Guide: Operating System and Devices.
File and Directory Access Modes in AIX 5L Version 5.2 System Management Guide: Operating System and Devices.
Linking Files and Directories in AIX 5L Version 5.2 System User's Guide: Operating System and Devices.