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
[USERNAME@host ~] echo -e 'prdxxx\ndadxxx' | grep "da*xxx"
[USERNAME@host ~] echo $SHELL
[USERNAME@host ~] dpkg -l | grep -iw bash
ii  bash                                    4.1-2ubuntu3                                    The GNU Bourne Again SHell
ii  bash-completion                         1:1.1-3ubuntu2                                  programmable completion for the bash shell
[USERNAME@host ~] 

Why does da*xxx find prdxxx too? It doesn't contains da... did I found a grep bug? or is this a feature?

share|improve this question
Related to your confusion, see Why do regular expressions differ from that used to filter files. – manatwork Jan 2 '13 at 11:48
up vote 9 down vote accepted

It is working fine as per the meaning of the '*'.

* -> 0 or more occurences of prev character.

Since you are checking for a*, this will match 0 or more a's. This means da*xxx can match dxxx, daxxx, daaxxx, daaaxxx, and so on.

share|improve this answer
why does "da*xxx" finds "prdxxx" string too? – gasko peter Jan 2 '13 at 8:11
becuase it contains dxxx. It does not matter what is before or after that. – Guru Jan 2 '13 at 8:13

There is a difference between normal shell file name patterns (called glob) where * matches any number of unknown characters, and regular expressions that are used for example by grep, where * stands for zero or more occurences of the previous pattern (this is the character a in your example).

share|improve this answer

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.