rm (Remove File)
The rm
(ReMove) command is used for deleting files. It is also used for deleting directories with the -r
(recursive) option.
Delete an existing file
Simply run the command with an existing file path. For example, to delete file_a under your working directory, run the command below.
rm file_a
-r (recursive) option
The -r
(recursive) option is used to delete an existing directory with contents (directories or files). As the rmdir
command cannot be used for a directory with files, this command is useful to remove a directory with files underneath.
If you want to delete dir_a under your working directory, run the command below.
rm -r dir_a
IMPORTANT
Files or directories deleted by the rm
command won't be recovered. This is different from the case where you put your files into the Trash Bin on Mac or Recycle Bin on Windows. (More precisely, there is a way to recover the deleted files or directories but it may not be successful. It is better to be careful before deleting any critical files with the rm
command.)