Sobes.tech
Senior

How to delete a file with a name starting with a hyphen (e.g., '-rf')?

sobes.tech AI

Answer from AI

Files with names starting with a dash are interpreted by commands as options, so they cannot be deleted directly using rm -rf. To delete such a file, you can:

  1. Use -- to indicate the end of options:
rm -- -rf
  1. Specify the path to the file, for example, through the current directory:
rm ./-rf
  1. Use the full or relative path to avoid interpreting the name as an option.

Any of these methods will allow you to delete a file with a name starting with a dash.

How to delete a file with a name starting with a… - sobes.tech