How to Delete a File Whose Name Starts with -- (Hyphens)

How to remove things like --filename

* This page contains promotional content

While I was working with Hugo, either because I got an argument wrong or because I built in View mode, a directory named “–bind=192.168.1.1” ended up being created

What does not work

When you try to delete a file or directory that starts with – (hyphens) like this, commands such as the ones below cannot remove it

$ rm --bind=192.168.1.1  # naturally this is mistaken for an argument, so ☓
$ rm ”--bind=192.168.1.1”   ☓
$ rm  '--bind=192.168.1.1'   ☓

The correct way to delete it

You insert “–” (two hyphens) into the command arguments and then specify the file or directory

$ rm -rf -- --bind=192.168.1.1
$ rm -- <filename>
$ rm -r -- <directory>
the same applies to mv for renaming
$ mv -- <filename>

By inserting the “–” (two hyphens) command argument, everything after it appears to be recognized as characters.

So rm -rf – –bind is interpreted as follows

command: rm
argument: -rf (force, directory)
argument: -- (no arguments are recognized after this)
directory name: --bind (treated entirely as characters)

It is a command argument you rarely use, so it is quite easy to forget