On 26-Dec-04 Chris Green wrote:
I tend always to use find when looking for files but recently discovered 'locate'.
However the 'locate' way of doing things strikes me a not very useful as it searches for the string you give it in every part of the filename which, in general, gives far too many hits.
E.g. if I do "locate organ" in the hope of finding some file containing organ music I get thousands of hits with 'Korganizer' etc. in. I also tried "locate -r '^organ" but that found nothing (which is also wrong).
"find / -name 'organ*'" does what I want (if slowly), is there any way of doing the same search with locate?
It's true that 'locate' finds everything therefore sometimes far too much, and also that 'find' can be slow (and also requires a specification which may be more specific than you can come up with at the time).
I use locate a lot, and when it does swamp me I try to filter out the excess.
E.g. in your example, having seen what
locate organ
comes up with, I would perhaps try
locate organ | grep -v Korgan
which would eliminate all of the "Korganiser" stuff.
Another useful type of filter is to select directories of interest, e.g. if you were only looking for executables you could filter for "bin":
locate organ | grep -v Korgan | grep bin
which would weed out all Korganiser and allow through all remaining files with "organ" in their pathname but, of these, only those with "bin" also in their pathname.
Hoping this helps, Ted.
-------------------------------------------------------------------- E-Mail: (Ted Harding) Ted.Harding@nessie.mcc.ac.uk Fax-to-email: +44 (0)870 094 0861 [NB: New number!] Date: 26-Dec-04 Time: 13:07:01 ------------------------------ XFMail ------------------------------