Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

When I'm in my home directory and type locate *.cpp I get hundreds of results.

Using the same command in (for example) ~/../forfun/netstream/, I see only a few results.

How is this possible?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

If you run locate *.cpp in the shell the shell will first try to expand *.cpp to all file names matching that pattern and then call locate with this file names as argument.

So if there are any .cpp files in your current directory locate will never see the *.cpp but only the file names it expands to.


locate '*.cpp'

if you don't want the shell to try to expand the pattern.

share|improve this answer

locate is a database-based finding method. It's damned fast but it's not thorough. I'd suggest using find which is comparatively a lot slower, but can do what you're after:

find /home/forfun/netstream/ -name '*.cpp'

Alternatively if you're happy with the output of locate but just want to trim it down, you can always pipe it through grep:

locate '*.cpp' | grep 'forfun/netstream'
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.