What does “–” (double-dash) mean? (also known as “bare double dash”)


Double dash:

  • The double dash “–” means end of command line flags i.e. it tells the preceding command not to try to parse what comes after command line options.
  • It is actually part of the POSIX standard that — can be used to separate options from other arguments, so you will see it on commands like cp and mv (which are not part of Bash).
  • — works to separate options from regular expressions in grep, but the canonical way is to use -e/–regexp

Example use:

you want to grep a file for the string -v – normally -v would be considered as the option to reverse the matching meaning (only show lines that do not match), but with — you can grep for string -v like this:

[pastacode lang=”bash” manual=”grep%20–%20-v%20file%20″ message=”Bash Code” highlight=”” provider=”manual”/]

A double dash ( — ) is used in bash built-in commands and there are more other commands to signify the end of command options, after which only positional parameters are accepted


Suppose you have a file named path/to/file.txt in my Git repository, and you want to revert changes on it.

[pastacode lang=”bash” manual=”git%20checkout%20path%2Fto%2Ffile.txt%0A” message=”Bash Code” highlight=”” provider=”manual”/]

Now suppose that the file is named master…

[pastacode lang=”bash” manual=”git%20checkout%20master%0A” message=”Bash Code” highlight=”” provider=”manual”/]

Whoops! That changed branches instead. The — helps to separate the tree you want to check out from the files you want to check out.

[pastacode lang=”bash” manual=”git%20checkout%20–%20master%0A%0A” message=”Bash Code” highlight=”” provider=”manual”/]

It also helps us if some freako added a file named -f to our repository:

[pastacode lang=”bash” manual=”git%20checkout%20-f%20%20%20%20%20%20%23%20wrong%0Agit%20checkout%20–%20-f%20%20%20%23%20right%0A” message=”Bash Code” highlight=”” provider=”manual”/]
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like

Should You Be Using a VPN for Gaming?

Most people have a passing knowledge of what a VPN is and what it does. The simplest way to explain it for those completely out of the loop is to say…
View Post