rm command (removes files or directories)
- Organization of this page
Format
rm [-d] [-f] [-i] [-R] [-r] path-name ...
Description
This command removes files or directories.
Arguments
- -d
-
Specifies that file or directory removal is to be performed. In the case of a directory, the entire directory is removed.
- -f
-
Specifies that file removal is to be performed without requesting confirmation. Nonexistent files are ignored. This option is ignored if it is specified before the -i option.
- -i
-
Specifies that confirmation is to be requested before removal is performed. Removal will be performed only if the reply y or Y is read from the standard input. This option is ignored if it is specified before the -f option.
- -R|-r
-
Specifies that a directory tree is to be removed recursively.
- path-name
-
Specifies a path name to be removed. Multiple path names can be specified.
Return codes
Return code |
Meaning |
---|---|
0 |
Normal termination
|
1 or greater |
Error termination |
Notes
-
In Windows, when you confirm removal without write permissions, non-access permissions other than the owner's are not displayed.
For details about the permissions that are displayed, see ls command (lists the contents of files or directories).
-
If the options -f and -i are both specified, the one specified last takes effect.
Usage examples
-
Specify the -i option to require confirmation before removing a file.
C:\TEMP>%ADSH_OSCMD_DIR%\rm -i file2.txt remove file2.txt?
-
Display an error message if the file does not exist.
C:\TEMP>%ADSH_OSCMD_DIR%\rm c.txt rm: c.txt: No such file or directory
-
Display an error message when you attempt to remove a directory without using the -d option.
C:\TEMP>%ADSH_OSCMD_DIR%\rm dir8 rm: dir8: is a directory
-
Display an error message when you attempt to remove a directory that contains files.
C:\TEMP>%ADSH_OSCMD_DIR%\rm -d dir8 rm: dir8: Directory not empty
-
Display an option error message.
This message might vary depending on the platform on which the command is executed. The following shows an example in Windows:
C:\TEMP>%ADSH_OSCMD_DIR%\rm -w rm: illegal option -- w usage: rm [-dfiRr] file ...