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

Unix Articles, Errors and Fixes
Unix Articles, Errors and Fixes
  • 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 will be considered the option to reverse the matching meaning (only show lines that do not match), but with — you can grep for string -v like this:

Bash Code
grep -- -v file 

A double dash ( — ) is used in bash built-in commands and many 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.

Bash Code
git checkout path/to/file.txt

Now suppose that the file is named master…

Bash Code
git checkout master

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

Bash Code
git checkout -- master

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

Bash Code
git checkout -f      # wrong
git checkout -- -f   # right

About the author

Wikitechy Editor

Add Comment

Click here to post a comment