rm Command

Purpose

The rm command removes or unlinks files or directories.

Syntax

rm [ -f ] [  -r ] [  -R ] [  -i ] [  -e ] File ...

Description

The rm command removes the entries for the specified File parameter from a directory. If an entry is the last link to a file, then the file is also deleted. The rm command prompts you to confirm before it deletes a file if you do not have write permission for the file and the standard input is a terminal. If you type a y (for yes), the file is deleted. If you type any other character, 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 that contains the file.

If the file is a symbolic link, the link is removed. However, the file or directory that the symbolic link refers to is not removed. You do not need write permission to delete a symbolic link, if you have write permission in the directory.

If . (dot) or .. (dot, dot) is 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 in the following scenarios:
  • The -f flag is not specified.
  • 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.

You cannot remove the files that are owned by other users if the sticky bit of the directory is set and the directory is not owned by you.

Note: The rm command supports the -- (dash, dash) parameter as a delimiter that indicates the end of the flags.

An attempt to remove a file or directory that is exported for use by the NFS version 4 server fails with a message that the resource is busy. The file or directory must be unexported for NFS version 4 use before it can be removed.

Flags

Table 1. Flags
Item Description
-e Displays a message after each file is deleted.
-f Does not prompt before it removes a write-protected file. Does not display an error message or return error status if a specified file does not exist. If both the -f and -i flags are specified, the last one specified takes effect.
-i Prompts you before it deletes each file. When you use the -i and -r flags together, the rm command also prompts before it deletes directories. If both the -i and -f flags are specified, the last one specified takes effect.
-r Permits recursive removal of directories and their contents when the File parameter is 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.

Exit status

This command returns the following exit values:

Table 2. Exit status
Item Description
0 If the -f flag is not specified, all the named directory entries are removed. Otherwise, all the existing named directory entries are removed.
>0 An error occurred.

Examples

  1. To remove the file /powervchome/backups/backup.tgz, enter the following command:
    rm  -f /powervchome/backups/backup.tgz
Notes:
  • No confirmation prompt is issued before the rm -f command internally 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.
  • No error message displays when the rm -f command attempts to remove nonexistent files.
  • Removing files in the following directories is allowed:
    • /home/pvcroot/ or $HOME directory of user
    • /tmp
    • /powervchome/diagnostics
    • /powervchome/backups
    • /powervchome/powervc-images
    • /powervclog
    • /var/log
  • It is allowed to delete the /powervcdata/opsmgr/powervc.lock file.