Wondering how to remove a file its name is "-f" or "-r" on Mac OS and on Linux. What is the right way to escape? I did some research and it seems the only way is to remove by inode ID?
thanks in advance, Lin
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
Larssend's solution (specifying a current directory before specifying the filename) works fine. Just to give you another solution, though:
rm -- -f
So, pass a parameter of two hyphens before specifying the challenging filename.
The -- means "quit trying to treat upcoming characters like options", so the hyphens will quit acting like special characters in the later parameters. Helps to ensure that a file that starts with a hyphen doesn't cause you to accidentally specify some unintended options. This is a program feature, not a shell feature, so support for this feature may vary between programs, but many standard Unix programs support it.