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 in home directory and type locate *.cpp I get hundreds of results. using the same command in (for example) ~/../forfun/netstream/ gets me a dozen results. how's that possible?

share|improve this question
add comment

2 Answers

up vote 0 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.

Use

locate '*.cpp'

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

share|improve this answer
add comment

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
add comment

Your Answer

 
discard

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.