IEEE P1003.2 Draft 11.2 - September 1991 Copyright (c) 1991 by the Institute of Electrical and Electronics Engineers, Inc. 345 East 47th Street New York, NY 10017, USA All rights reserved as an unpublished work. This is an unapproved and unpublished IEEE Standards Draft, subject to change. The publication, distribution, or copying of this draft, as well as all derivative works based on this draft, is expressly prohibited except as set forth below. Permission is hereby granted for IEEE Standards Committee participants to reproduce this document for purposes of IEEE standardization activities only, and subject to the restrictions contained herein. Permission is hereby also granted for member bodies and technical committees of ISO and IEC to reproduce this document for purposes of developing a national position, subject to the restrictions contained herein. Permission is hereby also granted to the preceding entities to make limited copies of this document in an electronic form only for the stated activities. The following restrictions apply to reproducing or transmitting the document in any form: 1) all copies or portions thereof must identify the document's IEEE project number and draft number, and must be accompanied by this entire notice in a prominent location; 2) no portion of this document may be redistributed in any modified or abridged form without the prior approval of the IEEE Standards Department. Other entities seeking permission to reproduce this document, or any portion thereof, for standardization or other activities, must contact the IEEE Standards Department for the appropriate license. Use of information contained in this unapproved draft is at your own risk. IEEE Standards Department Copyright and Permissions 445 Hoes Lane, P.O. Box 1331 Piscataway, NJ 08855-1331, USA +1 (908) 562-3800 +1 (908) 562-1571 [FAX] P1003.2/D11.2 INFORMATION TECHNOLOGY--POSIX 4.53 rm - Remove directory entries 4.53.1 Synopsis rm [-fiRr] _f_i_l_e ... 4.53.2 Description The rm utility shall remove the directory entry specified by each _f_i_l_e argument. If either of the files dot or dot-dot are specified as the basename portion of an operand (i.e., the final pathname component), rm shall write a diagnostic message to standard error and do nothing more with such operands. For each _f_i_l_e the following steps shall be taken: (1) If the _f_i_l_e does not exist: (a) If the -f option is not specified, write a diagnostic message to standard error. (b) Go on to any remaining _f_i_l_e_s. (2) If _f_i_l_e is of type directory, the following steps shall be taken: (a) If neither the -R option nor the -r option is specified, write a diagnostic message to standard error, do nothing more with _f_i_l_e, and go on to any remaining files. (b) If the -f option is not specified, and either the permissions of _f_i_l_e do not permit writing and the standard input is a terminal or the -i option is specified, write a prompt to standard error and read a line from the standard input. If the response is not affirmative, do nothing more with the current file and go on to any remaining files. (c) For each entry contained in _f_i_l_e, other than dot or dot- dot, the four steps listed here [(1)-(4)] shall be taken with the entry as if it were a _f_i_l_e operand. (d) If the -i option is specified, write a prompt to standard error and read a line from the standard input. If the response is not affirmative, do nothing more with the Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 686 4 Execution Environment Utilities Part 2: SHELL AND UTILITIES P1003.2/D11.2 current file, and go on to any remaining files. (3) If _f_i_l_e is not of type directory, the -f option is not specified, and either the permissions of _f_i_l_e do not permit writing and the standard input is a terminal or the -i option is specified, write a prompt to the standard error and read a line from the standard input. If the response is not affirmative, do nothing more with the current file and go on to any remaining files. (4) If the current file is a directory, rm shall perform actions equivalent to the POSIX.1 {8} _r_m_d_i_r() function called with a pathname of the current file used as the _p_a_t_h argument. If the current file is not a directory, rm shall perform actions equivalent to the POSIX.1 {8} _u_n_l_i_n_k() function called with a pathname of the current file used as the _p_a_t_h argument. If this fails for any reason, rm shall write a diagnostic message to standard error, do nothing more with the current file, and go on to any remaining files. The rm utility shall be able to descend to arbitrary depths in a file hierarchy, and shall not fail due to path length limitations (unless an operand specified by the user exceeds system limitations). 4.53.3 Options The rm utility shall conform to the utility argument syntax guidelines 2 described in 2.10.2. 2 The following options shall be supported by the implementation: -f Do not prompt for confirmation. Do not write diagnostic messages or modify the exit status in the case of nonexistent operands. Any previous occurrences of the -i option shall be ignored. -i Prompt for confirmation as described in 4.53.2. Any previous occurrences of the -f option shall be ignored. -R Remove file hierarchies. See 4.53.2. -r Equivalent to -R. Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 4.53 rm - Remove directory entries 687 P1003.2/D11.2 INFORMATION TECHNOLOGY--POSIX 4.53.4 Operands The following operand shall be supported by the implementation: _f_i_l_e A pathname of a directory entry to be removed. 4.53.5 External Influences 4.53.5.1 Standard Input Used to read an input line in response to each prompt specified in 4.53.6.1. Otherwise, the standard input shall not be used. 4.53.5.2 Input Files None. 4.53.5.3 Environment Variables The following environment variables shall affect the execution of rm: LANG This variable shall determine the locale to use for the locale categories when both LC_ALL and the corresponding environment variable (beginning with LC_) do not specify a locale. See 2.6. LC_ALL This variable shall determine the locale to be used to override any values for locale categories specified by the settings of LANG or any environment variables beginning with LC_. LC_COLLATE This variable shall determine the locale for the behavior of ranges, equivalence classes, and multicharacter collating elements used in the extended regular expression defined for the yesexpr locale keyword in the LC_MESSAGES category. LC_CTYPE This variable shall determine the locale for the interpretation of sequences of bytes of text data as characters (e.g., single- versus multibyte characters in arguments) and the behavior of character classes within regular expressions used in the extended regular expression defined for the yesexpr locale keyword in the LC_MESSAGES category. Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 688 4 Execution Environment Utilities Part 2: SHELL AND UTILITIES P1003.2/D11.2 LC_MESSAGES This variable shall determine the processing of affirmative responses and the language in which messages should be written. 4.53.5.4 Asynchronous Events Default. 4.53.6 External Effects 4.53.6.1 Standard Output None. 4.53.6.2 Standard Error Prompts shall be written to standard error under the conditions specified in 4.53.2 and 4.53.3. The prompts shall contain the _f_i_l_e pathname, but their format is otherwise unspecified. The standard error shall also be used for diagnostic messages. 4.53.6.3 Output Files None. 4.53.7 Extended Description None. 4.53.8 Exit Status The rm utility shall exit with one of the following values: 0 If the -f option was not specified, all the named directory entries were removed; otherwise, all the existing named directory entries were removed. >0 An error occurred. Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 4.53 rm - Remove directory entries 689 P1003.2/D11.2 INFORMATION TECHNOLOGY--POSIX 4.53.9 Consequences of Errors Default. BEGIN_RATIONALE 4.53.10 Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2) _E_x_a_m_p_l_e_s_,__U_s_a_g_e The _S_V_I_D requires that systems do not permit the removal of the last link to an executable binary file that is being executed. Thus, the rm utility can fail to remove such files. The -i option causes rm to prompt and read the standard input even if the standard input is not a terminal, but in the absence of -i the mode prompting is not done when the standard input is not a terminal. 1 For absolute clarity, paragraphs (2)(b) and (3) in 4.53.2, describing rm'_s behavior when prompting for confirmation, should be interpreted in the following manner: if ((NOT f_option) AND ((not_writable AND input_is_terminal) OR i_option)) It is forbidden to remove the names dot and dot-dot in order to avoid the consequences of inadvertently doing something like: rm -r .* The following command rm a.out core removes the directory entries a.out and core. The following command rm -Rf junk removes the directory junk and all its contents, without prompting. _H_i_s_t_o_r_y__o_f__D_e_c_i_s_i_o_n_s__M_a_d_e The exact format of the interactive prompts is unspecified. Only the general nature of the contents of prompts are specified, because implementations may desire more descriptive prompts than those used on historical implementations. Therefore, an application not using the -f Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 690 4 Execution Environment Utilities Part 2: SHELL AND UTILITIES P1003.2/D11.2 option, or using the -i option relies on the system to provide the most suitable dialogue directly with the user, based on the behavior specified. The -r option is existing practice on all known systems. The synonym -R option is provided for consistency with the other utilities in this standard that provide options requesting recursive descent. The behavior of the -f option in historical versions of rm is inconsistent. In general, along with ``forcing'' the unlink without prompting for permission, it always causes diagnostic messages to be suppressed and the exit status to be unmodified for nonexistent operands and files that cannot be unlinked. In some versions, however, the -f option suppresses usage messages and system errors as well. Suppressing such messages is not a service to either shell scripts or users. It is less clear that error messages regarding unlinkable files should be suppressed. Although this is historical practice, this standard does not permit the -f option to suppress such messages. When given the -r and -i options, historical versions of rm prompt the user twice for each directory, once before removing its contents and once before actually attempting to delete the directory entry that names it. This allows the user to ``prune'' the file hierarchy walk. Historical versions of rm were inconsistent in that some did not do the former prompt for directories named on the command line and others had obscure prompting behavior when the -i option was specified and the permissions of the file did not permit writing. The POSIX.2 rm differs little from historic practice, but does require that prompts be consistent. Historical versions of rm were also inconsistent in that prompts were done to both standard output and standard error. POSIX.2 requires that prompts be done to standard error, for consistency with cp and mv and to allow existing extensions to rm that provide an option to list deleted files on standard output. The rm utility is required to descend to arbitrary depths so that any file hierarchy may be deleted. This means, for example, that the rm utility cannot run out of file descriptors during its descent, i.e., if the number of file descriptors is limited, rm cannot be implemented in the historical fashion where a file descriptor is used per directory level. Also, rm is not permitted to fail because of path length restrictions, unless an operand specified by the user is longer than {PATH_MAX}. END_RATIONALE Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 4.53 rm - Remove directory entries 691 P1003.2/D11.2 INFORMATION TECHNOLOGY--POSIX 4.54 rmdir - Remove directories 4.54.1 Synopsis rmdir [-p] _d_i_r ... 4.54.2 Description The rmdir utility shall remove the directory entry specified by each _d_i_r operand, which shall refer to an empty directory. Directories shall be processed in the order specified. If a directory and a subdirectory of that directory are specified in a single invocation of the rmdir utility, the subdirectory shall be specified before the parent directory so that the parent directory will be empty when the rmdir utility tries to remove it. 4.54.3 Options The rmdir utility shall conform to the utility argument syntax guidelines described in 2.10.2. The following option shall be supported by the implementation: -p Remove all directories in a pathname. For each _d_i_r operand: (1) The directory entry it names shall be removed. (2) If the _d_i_r operand includes more than one pathname component, effects equivalent to the following command shall occur: rmdir -p $(dirname _d_i_r) 4.54.4 Operands The following operand shall be supported by the implementation: _d_i_r A pathname of an empty directory to be removed. Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 692 4 Execution Environment Utilities