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:
- Use
--to indicate the end of options:
rm -- -rf
- Specify the path to the file, for example, through the current directory:
rm ./-rf
- 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.