The easiest way is to write a simple shell script which combines locate and grep:
Create a file somewhere in your $PATH (e.g. /usr/local/bin/clocate) with
#!/bin/sh
locate --regex "$1" | grep --color=auto "$1"
then make it executable, e.g.
chmod +x /usr/local/bin/clocate
and use it like locate. The script does only accept one pattern.
Another way is to use a shell function: If you are using bash as your shell, you can add to your $HOME/.bashrc the following line:
clocate() { locate --regex "$1" | grep --color=auto "$1"; }
You need to rerun bash or re-source your .bashrc before you can the new command.
Please note the --regex option for locate. You need to write .* instead of * to match any number of characters.
alias locate=clocateafter that function on.bashrc. – Pablo A Jul 15 '17 at 02:08