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
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
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.
You can use rm ./'-f' and rm ./'-r', rm -i ./*, or rm -i ./-*. These solutions are widely known.