rm or delete Command Purpose Removes (unlinks) files or directories. Syntax { rm | delete } [ -f ] [ -r ] [ -R ] [ -i ] [ -e ] [ -- ] File ... Description The rm command removes the entries for the specified file or files 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 permis- sion for the file you want to remove. However, you must have write permission for the directory containing that file. If a file has no write permission specified and standard input is a workstation, the rm command displays the file-permission code and reads a line from standard input. If that line begins with a y or the locale's equivalent of a y, the rm command deletes the file. If the response is anything other than a y, the rm command does nothing to that file and continues with the next specified file. Flags -e Displays a message after each file is deleted. -f Does not prompt before removing a write-protected file. -i Prompts you before deleting each file. When you use the -i and -r flags together, the rm command also prompts before delet- ing directories. -r Permits recursive removal of directories and their contents when the File parameter specifies a directory. This flag is equivalent to the -R flag. -R Permits recursive removal of directories and their contents when the File parameter is a directory. This flag is equivalent to the -r flag. - - Indicates that all arguments following it are to be treated as file names. This allows you to specify file names starting with one - (dash). Exit Status This command returns the following exit values: 0 If the -f option was not specified, all the named directory en- tries were removed; otherwise, all the existing named directory entries were removed. >0 An error occurred. Examples 1. To delete a file, enter: 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. 2. To delete a file silently, enter: rm -f core No confirmation prompt is issued before the rm -f command at- tempts to remove the file named core. However, an error message will be displayed 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 is displayed when the rm -f command attempts to re- move nonexistent files. 3. To delete files one by one, enter: rm -i mydir/* After each file name is displayed, enter y to delete the file, or press the Enter key to keep it. 4. To delete a directory tree, enter: rm -ir manual This 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: y Here, the rm command first asks if you want it to search the manual directory. Because the manual directory contains direc- tories, 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 direc- tory. Instead, you see the message rm: Directory manual not emp- ty. Implementation Specifics This command is part of Base Operating System (BOS) Runtime. Files /usr/bin/rm Contains the rm command. /usr/bin/delete Contains the delete command. Related Information Directory Overview in AIX Version 3.2 System User's Guide: Base and Devices. Understanding File and Directory Access Modes in AIX Version 3.2 System Management Guide: Operating System and Devices. Linking Files and Directories in AIX Version 3.2 System User's Guide: Base and Devices. The del command, ln command. The unlink subroutine.