How to Remove Files Start with Double Dash in Linux

Question

Hello! I need a little help. I am trying to remove a file with the rm command in terminal. But the file name start with a double dash and I get the following error when try to remove.

rm: unrecognized option '--filename'

Answer

Just use period and forward slash (./) before the file name as bellow to tell rm command that this is a file inside the current working directory, not a command line option (since double dash Use for command options).

rm -rf ./--filename

Also, you can use the absolute path of the file name. For example, assuming that your file is located inside the /var/log directory, you can do is as follows.

rm /var/log/--filename

In Linux Commands, Double dash is used for Command options. That is why the reason error happened in the first place.