find as suggested in Scott Wilson's answer is what I would have used. However, if you really need to use the locate DB, a hackish solution could be
sudo strings /var/lib/mlocate/mlocate.db | grep -E '^/.*dirname'
sudo since the database is not directly readable by regular users.
strings to strip metadata (this makes you also find directories to which you don't have read permission, which
locate usually hinders).
/var/lib/mlocate/mlocate.db is the DB path on Ubuntu, apparently (as an example. Other distributions might have it in other places, e.g.
grep -E to enable regular expressions.
^/.*dirname will match all lines that start with a
/, which all directories in the DB happen to do, followed by any character a number of times, followed by your search word.
Positive sides of this solution:
- it is faster than
- you can use all the bells and whistles of
grep (or other favourite text processing tools).
- the same as
locate in general (DB must be updated),
- you need root access.