- How do you remove a file whose filename begins with a dash (hyphen or minus) -? You are ssh’d into a remote OSX server and you have this file in your directory:
- How in the world can you delete –help from a CLI? This issue is something that you come across in different forms on occasion, these files are easy to create, but hard to get rid of you have tried using backslash.
I have tried quotes
- How do you prevent the minus (dash or hyphen) character to be interpreted as an option?
- Use “–” to make rm stop parsing command line options, like this:
Or you can do
Use find to do it:
- If you have more then a few files like this that you can delete you can get a preview list of the files by simply running find without the -delete option first, and then if the list of files look good just run it again with -delete.
- In fact, you avoiding rm in favor of find (especially with preview first) that will help you to avoid mistakes with rm * that will inevitably bite you some day.
- That find will recurse through all your subdirectories, so you might want to run it with a subdirectory depth constraint like this:
- which limits the find to the current directory.