While working with a Linux admin, he introduced me to the Linux ‘Locate’ command, which until now I had not seen or used. The ‘locate’ command works much like the ‘find’ and is a quick and easy way to find files on the system. We were using ‘locate’ to discover files within the server and the commands simplicity proved useful to me.
When the locate command is used without any options, the locate command displays every absolute pathname for which the user has access permission that contains any of the names of files and/or directories for the identified file. So, it is important to know what rights your user has or better yet user the command as root or root sudo. Otherwise, existing files can be omitted do to permissions restrictions. Also, the scope of the results is broader than and, usually, more complete than the find command.
Syntax for locate command
- locate [options] name(s)
Example Locate command
When run as root this command returns all occurrences of the ‘odbc.ini’ file and their absolute path.
- Locate odbc.ini
Locate Command Results
Same Search Utilizing the Find Command
Not only is the find command more complex for the purpose, but the results are more narrow in there information return.
Example Find command
- find -type f -name odbc.ini
Find command Results