When I run locate syn, it will return files with syn appearing in their file names.
How can I search for files with full name syn? Is locate --regex syn$ the correct way, while locate --regex ^syn$ isn't?
The --regex option applies to the entire path, not just the file name. So, locate --regex syn$ will match all files and directories whose path, including their name, ends in syn while locate --regex syn$ will only match a file whose entire path is syn and such a file does not exist:
$ locate --regex ^etc$ ## returns nothing
$ locate --regex ^/etc$
/etc
The option you're looking for is -b:
-b, --basename
Match only the base name against the specified patterns. This
is the opposite of --wholename.
You could, therefore, do
locate -b --regex ^sys$
That will list all files and folders in locatedb whose name is exactly sys.
synat the beginning of the line, do you? Trylocate --regex '/syn$'. – jimmij Mar 17 '15 at 14:50