Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So under Linux/AIX where ever.., when is it useful to use:


the Question is the "--" part. When is it usefull to use?

share|improve this question
up vote 16 down vote accepted

When "SOMEPATTERN" starts or may start (for instance if it's a variable like "$PATTERN" which you don't have full control on) with a - (dash) character.

Also with GNU grep (unless $POSIXLY_CORRECT is on), it's useful if other arguments (file names) may start with -.

Alternatively, you can do

grep -e -SOMEPATTERN- -- file1 file2 -xxx-

-- marks the end of options. It's useful everywhere where non-option arguments may start with a dash, and it doesn't harm, so it's a good habit to use it.

share|improve this answer

When the pattern starts with a dash, otherwise grep will think it is an option. Say, you are looking for "-a" in a text:

grep -a file.txt

grep will then try to find the pattern "file.txt" in the standard input, using the option -a. Therefore, you need to do

grep -- -a file.txt
share|improve this answer
This does not only hold for grep. – Bernhard Oct 11 '12 at 10:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.