Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

1 Answer

up vote 1 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
add comment

Your Answer

 
discard

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