{"id":13402,"date":"2019-04-01T23:53:53","date_gmt":"2019-04-01T23:53:53","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13402"},"modified":"2019-04-01T23:53:53","modified_gmt":"2019-04-01T23:53:53","slug":"how-to-install-locate-command-to-find-files-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/how-to-install-locate-command-to-find-files-in-linux\/","title":{"rendered":"How to Install \u2018locate Command\u2019 to Find Files in Linux"},"content":{"rendered":"<p>The\u00a0<a href=\"https:\/\/www.tecmint.com\/linux-locate-command-practical-examples\/\" target=\"_blank\" rel=\"noopener\">locate<\/a>\u00a0is a command line utility for finding files by name in Linux, just like\u00a0<a href=\"https:\/\/www.tecmint.com\/35-practical-examples-of-linux-find-command\/\" target=\"_blank\" rel=\"noopener\">find command<\/a>. However, it works more efficiently compared to its counterpart; it uses one or more databases populated by the\u00a0<strong>updatedb<\/strong>\u00a0program and prints file names matching at least one of the patterns (a user provides) to standard output.<\/p>\n<p>Locate package is provided by the\u00a0<strong>GNU findutils<\/strong>\u00a0or\u00a0<strong>mlocate<\/strong>\u00a0packages. These packages are known to provide the same implementation of the program. On most\u00a0<strong>CentOS\/RHEL<\/strong>\u00a0systems,\u00a0<strong>findutils<\/strong>\u00a0comes pre-installed, however, if you try to run a\u00a0<a href=\"https:\/\/www.tecmint.com\/linux-locate-command-practical-examples\/\" target=\"_blank\" rel=\"noopener\">locate command<\/a>, you may encounter the error:<\/p>\n<pre>-bash: locate: command not found\r\n<\/pre>\n<p>In this article, we will show you how to install\u00a0<strong>mlocate<\/strong>\u00a0package which provides the\u00a0<strong>locate<\/strong>\u00a0and\u00a0<strong>updatedb<\/strong>commands to find files in Linux systems.<\/p>\n<p>Below is a sample output showing the above error and querying\u00a0<strong>findutils<\/strong>\u00a0package.<\/p>\n<pre>$ locate bash_completion.sh\r\n$ rpm -qa | grep findutils\r\n<\/pre>\n<div id=\"attachment_27888\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/Locate-Command-Not-Found.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27888\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/Locate-Command-Not-Found.png\" alt=\"Locate Command Not Found\" width=\"622\" height=\"116\" aria-describedby=\"caption-attachment-27888\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-27888\" class=\"wp-caption-text\">Locate Command Not Found<\/p>\n<\/div>\n<p>To install\u00a0<strong>mlocate<\/strong>, use the\u00a0<a href=\"https:\/\/www.tecmint.com\/20-linux-yum-yellowdog-updater-modified-commands-for-package-mangement\/\" target=\"_blank\" rel=\"noopener\">YUM<\/a>\u00a0or\u00a0<a href=\"https:\/\/www.tecmint.com\/apt-advanced-package-command-examples-in-ubuntu\/\" target=\"_blank\" rel=\"noopener\">APT<\/a>\u00a0package manager as per your Linux distribution as shown.<\/p>\n<pre>$ sudo yum install mlocate    [On CentOS\/RHEL]\r\n$ sudo apt install mlocate    [On Debian\/Ubuntu]     \r\n<\/pre>\n<p>After installing\u00a0<strong>mlocate<\/strong>, you need to update the\u00a0<strong>updatedb<\/strong>, which is used by\u00a0<strong>locate<\/strong>\u00a0command as root user with the\u00a0<a href=\"https:\/\/www.tecmint.com\/su-vs-sudo-and-how-to-configure-sudo-in-linux\/\" target=\"_blank\" rel=\"noopener\">sudo command<\/a>, otherwise you will get an error. The default database storage location is\u00a0<strong>\/var\/lib\/mlocate\/mlocate.db<\/strong>.<\/p>\n<pre>$ sudo updatedb\r\n<\/pre>\n<p>Once the database is updated, now try to run the\u00a0<strong>locate<\/strong>\u00a0command, which should work this time around.<\/p>\n<pre>$ locate bash_completion.sh\r\n<\/pre>\n<div id=\"attachment_27889\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/Find-Files-Using-Locate.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27889\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/Find-Files-Using-Locate.png\" alt=\"Find Files Using Locate Command\" width=\"622\" height=\"59\" aria-describedby=\"caption-attachment-27889\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-27889\" class=\"wp-caption-text\">Find Files Using Locate Command<\/p>\n<\/div>\n<p>To find an exact match according to pattern you enter, use this\u00a0<code>-b<\/code>\u00a0option and the\u00a0<code>\\<\/code>\u00a0globbing option as in the following syntax.<\/p>\n<pre>$ locate -b '\\bash_completion.sh'\r\n<\/pre>\n<p><strong>Note<\/strong>: You can use the\u00a0<strong>LOCATE_PATH<\/strong>\u00a0environmental variable to set a path to extra databases, which are read after the default database or any databases listed using the\u00a0<strong>\u2013database<\/strong>\u00a0flag on the command line.<\/p>\n<p>That\u2019s all! In this guide, we showed you how to install\u00a0<strong>mlocate<\/strong>\u00a0package which offers the\u00a0<strong>locate<\/strong>\u00a0and\u00a0<strong>updatedb<\/strong>commands on a Linux system. Share your views with us through the feedback form below.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/install-locate-command-to-find-files-in-centos\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The\u00a0locate\u00a0is a command line utility for finding files by name in Linux, just like\u00a0find command. However, it works more efficiently compared to its counterpart; it uses one or more databases populated by the\u00a0updatedb\u00a0program and prints file names matching at least one of the patterns (a user provides) to standard output. Locate package is provided by &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/how-to-install-locate-command-to-find-files-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Install \u2018locate Command\u2019 to Find Files in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13402","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13402","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=13402"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13402\/revisions"}],"predecessor-version":[{"id":13404,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13402\/revisions\/13404"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13402"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13402"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13402"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}