Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

I have found that sometime i can find files using locate but sometimes it dont find.

Which directories it find the file using locate or find

Suppose i want to find the files or directories having word denyhosts.

Whats the best way to find that

share|improve this question
up vote 3 down vote accepted

Locate has to be feeded every then and now to have a updated list of everything on your server.

To keep it up-to-date you have to run updatedb command.

If after you ran that command you have create or download or increased the amount of new files it won't be listed in there so locate won't find it.

With find aslong as you know what you are looking for you will find it.

For example:

find / -name denyhosts\*

Would look for a file starting with denyhosts on every directory from / and above.

To look for directories only use the -type d option, like this:

find / -name denyhosts* -type d

The above will look from /and above for a directory name starting with denyhosts.

I prefer having updatedb up-to-date i guess it is easier to find things, but that is just my personal preference, it works just like a cache so once it is updated to find things it might be even faster.

share|improve this answer
How can i search for only directories using locate command – John Oct 12 '10 at 3:12
For that you should use find, find / -name denyhosts\* -type d the later -type d means to look for directories – Prix Oct 12 '10 at 3:56
thanks for that – John Oct 12 '10 at 4:16
the command locate was not designed to tell you what is file and what is folder hence why you should use find, to use locate to detect folder you would need more then locate alone, which would make it not a good option considering you have FIND. – Prix Oct 12 '10 at 5:06

Your Answer


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