Search code examples
linuxbashshellunixrm

How to delete file whose name begins with "--"?


I create a file named "--address=16.187.249.27" by accident, and try following methods to delete it, but no success:

$ rm "--address=16.187.249.27"
rm: unrecognized option '--address=16.187.249.27'
Try 'rm ./'--address=16.187.249.27'' to remove the file ‘--address=16.187.249.27’.
Try 'rm --help' for more information.

$ rm "\--address=16.187.249.27"
rm: cannot remove ‘\\--address=16.187.249.27’: No such file or directory

How to delete file whose name begins with "--"?


Solution

  • Adding a single instance of -- to your command line means that everything that comes after is file names and not flag arguments. So this should do it:

    rm -- --address=16.187.249.27