{"id":6702,"date":"2022-10-02T12:54:29","date_gmt":"2022-10-02T12:54:29","guid":{"rendered":"https:\/\/www.geekdecoder.com\/?p=6702"},"modified":"2022-10-02T12:54:29","modified_gmt":"2022-10-02T12:54:29","slug":"how-to-locate-files-in-linux-with-mlocate","status":"publish","type":"post","link":"https:\/\/www.qbytes.cloud\/index.php\/2022\/10\/02\/how-to-locate-files-in-linux-with-mlocate\/","title":{"rendered":"How to Locate files in Linux with mlocate"},"content":{"rendered":"<p>This article show how to locate file easily in Linux. To install and update mlocate so as to use immediately.<br \/>\n<!--more--><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n$ sudo apt install mlocate\nReading package lists... Done\nBuilding dependency tree... Done\nReading state information... Done\nSuggested packages:\n  nocache\nThe following NEW packages will be installed:\n  mlocate\n0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.\nNeed to get 98.3 kB of archives.\nAfter this operation, 517 kB of additional disk space will be used.\nGet:1 http:\/\/deb.debian.org\/debian bullseye\/main amd64 mlocate amd64 0.26-5 &#x5B;98.3 kB]\nFetched 98.3 kB in 0s (558 kB\/s)\nSelecting previously unselected package mlocate.\n(Reading database ... 30418 files and directories currently installed.)\nPreparing to unpack ...\/mlocate_0.26-5_amd64.deb ...\nUnpacking mlocate (0.26-5) ...\nSetting up mlocate (0.26-5) ...\nupdate-alternatives: using \/usr\/bin\/mlocate to provide \/usr\/bin\/locate (locate) in auto mode\nAdding group `mlocate' (GID 114) ...\nDone.\nCreated symlink \/etc\/systemd\/system\/timers.target.wants\/mlocate.timer \u2192 \/lib\/systemd\/system\/mlocate.timer.\nmlocate.service is a disabled or a static unit, not starting it.\nProcessing triggers for man-db (2.9.4-2) ...\n<\/pre>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n$ man mlocate\n<\/pre>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\nNAME\n       locate - find files by name\n\nSYNOPSIS\n       locate &#x5B;OPTION]... PATTERN...\n\nDESCRIPTION\n       locate reads one or more databases prepared by updatedb(8) and writes file names matching at\n       least one of the PATTERNs to standard output, one per line.\n\n       If --regex is not specified, PATTERNs can contain globbing characters.  If any PATTERN  con\u2010\n       tains no globbing characters, locate behaves as if the pattern were *PATTERN*.\n\n       By  default,  locate does not check whether files found in database still exist (but it does\n       require all parent directories to exist if the database was built with  --require-visibility\n       no).   locate  can  never  report files created after the most recent update of the relevant\n       database.\n....\nSEE ALSO\n       updatedb(8)\n<\/pre>\n<p>So, now it is installed, lets locate something.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n$ cd ~\/\n$ echo &quot;My File!&quot; &gt; mylocatefile.txt\n$ locate mylocatefile.txt\n<\/pre>\n<p>ok, so there is an error&#8230;<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nlocate: can not stat () `\/var\/lib\/mlocate\/mlocate.db': No such file or directory\n<\/pre>\n<p>We must update the database first in order to use it. This is in the man page updatedb:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nman updatedb\nNAME\n       updatedb - update a database for mlocate\n\nSYNOPSIS\n       updatedb &#x5B;OPTION]...\n\nDESCRIPTION\n       updatedb creates or updates a database used by locate(1).  If the database already exists, its\n       data is reused to avoid rereading directories that have not changed.\n\n<\/pre>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n$ sudo updatedb\n<\/pre>\n<p>Now we can search for files.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n$ locate mylocatefile.txt\n\/home\/ipfs\/mylocatefile.txt\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This article show how to locate file easily in Linux. To install and update mlocate so as to use immediately.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,58],"tags":[139],"class_list":["post-6702","post","type-post","status-publish","format-standard","hentry","category-administration","category-linux","tag-linux"],"_links":{"self":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/6702","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/comments?post=6702"}],"version-history":[{"count":0,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/6702\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/media?parent=6702"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/categories?post=6702"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/tags?post=6702"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}