What does "--" mean in terminal commands?

I have seen many tutorials that use a -- after commands. Something like this:

command -- 

What does this -- mean?


Solution 1:

The -- is used to indicate the end of command line options. This enables you to use arguments starting with --. For example, if you create a file called --foo:

$ > '--foo'
$ ls
--foo

And then try to delete it, rm will think you're giving it an argument:

$ rm --foo 
rm: unrecognized option '--foo'
Try 'rm ./--foo' to remove the file '--foo'.
Try 'rm --help' for more information.

One way around this is to use --:

$ rm -- --foo

This is common practice and recommended by POSIX, so it's supported by many programs.

Solution 2:

Most commands will use a -- to tell the command that further parameters should be treated differently. One example is the rm -- --filename noted above. Another example, a script like 'startx' will interpret itself everything before -- , and pass everything after it to the X server.