rm Command - Delete File

You can delete the file using the rm command. rm comes from remove.

rm FileName

Try deleting the file foo.txt using the rm command.

rm foo.txt

Delete directory and all its contents - "-r" option of rm command

To remove the directory and all its contents, use the "-r" option of the rm command. "-R" comes from recursive.

rm -r DirectoryName

This command will delete the directory and all the files in it, so be careful.

Forcibly delete files - "-f" option of rm command

If you try to delete a file with the rm command, you may be asked if you want to delete the file.

Even in such a case, if you want to delete it without confirmation, use the "-f" option of the rm command. "-F" comes from force.

rm -rf DirectoryName

Be careful when using this command as it will delete the directory and all the files in it without confirmation.

Show help --help option

Use the "--help" option to get help.

rm --help

Help is displayed.

Usage: rm [OPTION] ... FILE ...
Remove (unlink) the FILE (s).

  -f, --force ignore nonexistent files, never prompt
  -i, --interactive prompt before any removal
      --no-preserve-root do not treat `/'specially (the default)
      --preserve-root fail to operate recursively on `/'
  -r, -R, --recursive remove directories and their contents recursively
  -v, --verbose explain what is being done
      --help display this help and exit
      --version output version information and exit

Associated Information