locate command lets you easily find files in the filesystem. It works by maintaining a system-wide database of "all files which are publicly accessible". The database itself is updated periodically by a background process. Because of this approach it returns results much faster than the
find command, which only looks for files when you tell it to. Depending on your system, the
locate command may need to be configured initially, or it may be pre-configured to work out of the box.
locate command is easy to use. If you want to find a file named "foo", just use this locate syntax:
locate command returns all files it knows whose name contains the string "foo", like "foo1", "foobar", etc.
You can also use the usual filename wildcard characters, including
*. For instance, this locate example command will list every Java file on your system:
(Be prepared, that can be a very long list.)
Finally, you can also perform a case-insensitive search using the
locate command with the
-i argument, like this locate command example:
locate -i "*.java"
As mentioned, the
find command can also be used to find files and directories.
This website is a little one-man operation. If you found this information helpful, I’d appreciate it if you would share it.