On Tue, 25 Mar 2014, Jeff Chapin wrote:

> On Mon, Mar 24, 2014 at 5:45 PM, paul g <pj.world at hotmail.com> wrote:
>
>> why when I do a 'locate firefox' in terminal many entries show up? A 
>> few more than listed below but this is the just of it.
>
> The 'locate' command uses a pre-created database of file names. If you 
> have not re-run 'updatedb' after creating a file, 'locate' will not know 
> about it. Locate will return any file that matches the pattern you gave 
> it.

Also, with "locate", the default is to match any pattern in the entire 
path to a file or directory.  Example:

locate bin | less

The name of the file or directory itself, excluding parent directories in 
its path, is called its basename.  There is an option in "locate" to 
search only the basename.  From "man locate":

   -b, --basename
         Match only the base name against the specified patterns. This
         is the opposite of --wholename.

   -w, --wholename
         Match only the whole path name against the specified patterns.
         This is the default behavior.  The opposite can be specified
         using --basename.

I have a lot of small files on my system, but I still see a very dramatic 
drop in the number of matches when I use the -b option:

$ locate bin | wc -l
28241

$ locate -b bin | wc -l
4826


It's not quite relevant to the question about "locate", but I'll mention 
that there is a program called "basename" (and another called "dirname"):


Usage: basename NAME [SUFFIX]
   or:  basename OPTION
Print NAME with any leading directory components removed.
If specified, also remove a trailing SUFFIX.

       --help     display this help and exit
       --version  output version information and exit

Examples:
   basename /usr/bin/sort       Output "sort".
   basename include/stdio.h .h  Output "stdio".



Usage: dirname NAME
   or:  dirname OPTION
Print NAME with its trailing /component removed; if NAME contains no /'s,
output `.' (meaning the current directory).

       --help     display this help and exit
       --version  output version information and exit

Examples:
   dirname /usr/bin/sort  Output "/usr/bin".
   dirname stdio.h        Output ".".