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
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.
find / -name denyhosts\* -type d
the later -type d means to look for directories
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.