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

When using grep -r you could search in all files with either * or . and it seems to return the same thing but is it really the same?

Let's say I search for "foo", then I could write

grep -r foo *


grep -r foo .

Would anyone try to explain the difference between . and *?

share|improve this question
up vote 15 down vote accepted

grep -r foo * doesn't look for matches in hidden files or directories, also * is expanded by the shell so you might end up with an Argument list too long error when there are a lot of entries in the current directory, or some other errors or misbehaviour if the name of some of the files or directories starts with a dash character.

Invocation grep -r foo . doesn't have the above flaws


Another difference: grep's man page (@fedora17) says:

-r, --recursive
    Read all files under each directory, recursively, following symbolic links only if they
    are on  the  command  line.  ...

There will be also a difference when you execute this command in an empty directory:

$ grep -r foo *; echo $?
grep: *: No such file or directory
$ grep -r foo .; echo $?
share|improve this answer

If you use asterisk, you cannot match files in directories whose name start with a dot, like .cache.


This is because the * is expanded by the shell before calling grep, so it receive a list of names instead of a single directory name (for the current .). The way shell expand the pattern may be customized with shell parameter (as for nullglob, nocaseglob or other bash options) or be environment variables (like LANG or LC_ALL)

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.