4

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

1 Answer 1

4

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.

3
  • How can i search for only directories using locate command
    – John
    Commented Oct 12, 2010 at 3:12
  • For that you should use find, find / -name denyhosts\* -type d the later -type d means to look for directories
    – Prix
    Commented Oct 12, 2010 at 3:56
  • 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
    Commented Oct 12, 2010 at 5:06

You must log in to answer this question.