I wish to have the command locate in ubuntu 12.04 (which is used for finding files. I believe there is such a command but I cannot see it in ubuntu 12.04 Is it part of any package?
Asked
Active
Viewed 2.3e+01k times
101
Evandro Silva
- 9,942
JVIyer
- 1,011
- 2
- 7
- 3
2 Answers
136
sudo apt-get install mlocate should install the 'locate' command.
mlocate maintains a database of all your files and is re-indexed once a day by default. If you want it to re-index immediately then run sudo updatedb from the command line.
If you get a cannot stat error when you run locate, then you need to run sudo updatedb to populate the database, just as if you wanted to re-index immediately.
From Ubuntu 22.04 onwards, mlocate is a transitional dummy package that installs plocate, so you can run sudo apt-get install plocate instead to install plocate directly.
muru
- 207,970
Thomas Ward
- 80,112
-
7I believe that the mlocate package installs a mlocate job in /etc/cron.daily which runs updatedb daily. – mfisch Nov 11 '12 at 02:20
-
2Just after you do that, if you try to call locate, you will get the following error: "locate: can not stat () `/var/lib/mlocate/mlocate.db': No such file or directory". To solve that, please refer to @enxotib response in: http://unix.stackexchange.com/questions/26188/how-do-i-enable-locate-and-queue-the-database-to-be-built – Ramon Araujo May 12 '14 at 04:02
-
You probably want to run
sudo updatedbafter installing mlocate, since the search database needs to be optimized for first time use. – IgorGanapolsky Apr 10 '16 at 20:48 -
1If you're on CentOS/RHEL/Amazon Linux, use
sudo yum install mlocateto install it. Also the same, runsudo updatedbto initialize the database for the first time. – ADTC May 06 '18 at 00:42 -
2Warning: At least on pop_os! 22.04
mlocateis a transitional dummy package toplocate, which have some advantages but have fewer features (like--transliterate) – Pablo Bianchi Nov 22 '22 at 22:57 -
1
13
martinho
- 277
-
2Thanks for the updated answer, I'm doing this install right now. Why is it better, links to some source? It helps to provide some context when you say "better" that sounds subjective. – JimLohse Aug 14 '23 at 23:38
-
1
sudo apt-get install locate. – Evandro Silva Nov 10 '12 at 20:24sudo apt-get install apt-fileand search for the program using apt-file:apt-file search /usr/bin/locate. – hnasarat Nov 10 '12 at 20:57locateis already installed in a standard Ubuntu install anyway, so maybe this doesn't help. – thomasrutter May 28 '13 at 03:15locatethat keeps dis-/re-appearing, andplocate, which (arguably) might be an improved (or the same as)locate, and there'smlocatewhich might be its own thing or just a dummy package forplocateorlocatebut now seems to be gone, and wasn't there iir aslocateat some point? aaaack – michael Jan 12 '24 at 04:06