-
To find any pathname that ends with bin:
% locate '*bin'
/bin
/home/robin
/home/robin/bin
...
-
To find any pathname that ends with /bin (a good
way to find a file or directory named exactly
bin):
% locate '*/bin'
/bin
/home/robin/bin
/usr/bin
...
-
Typing locate '*bin*' is the same as typing
locate bin.
-
To match the files in a directory named bin, but
not the directory itself, try something like this:
% locate '*/bin/*'
/bin/ar
/bin/cat
...
/home/robin/bin/prog
-
To find the files in /home whose names end with
a tilde (~) (these are probably backup files from
the Emacs editor):
% locate '/home/*~'
/home/testfile~
/home/allan/.cshrc~
/home/allan/.login~
/home/dave/.profile~
...
Notice that the locate asterisk matches dot
files, unlike shell wildcards.
-
The question mark (?) and square brackets
([ ]) operators work, too.
They're not quite as useful as they are in the shell
because they match the slashes (/) in the
pathnames. Here are a couple of quick examples:
% locate '????'
/bin
/etc
/lib
/src
/sys
/usr
% locate '/[bel]??'
/bin
/etc
/lib