94

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?

4
  • 1
    Try using this command: sudo apt-get install locate. Nov 10, 2012 at 20:24
  • 5
    For the future: if you're looking for a program and don't know the package, install apt-file: sudo apt-get install apt-file and search for the program using apt-file: apt-file search /usr/bin/locate.
    – hnasarat
    Nov 10, 2012 at 20:57
  • In a standard Ubuntu install this often isn't needed - if you type a command on the command-line that Ubuntu doesn't know, it'll often suggest which package to install to get that command. Come to mention it, I think locate is already installed in a standard Ubuntu install anyway, so maybe this doesn't help. May 28, 2013 at 3:15
  • this is actually an unfortunately perpetually useful question (and not at all a "just install it" question), as this particular utility keeps changing names for whatever reason (and has cross-platform variations). There's locate that keeps dis-/re-appearing, and plocate, which (arguably) might be an improved (or the same as) locate, and there's mlocate which might be its own thing or just a dummy package forplocate or locate but now seems to be gone, and wasn't there iir a slocate at some point? aaaack
    – michael
    Jan 12 at 4:06

2 Answers 2

128

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.

6
  • 7
    I believe that the mlocate package installs a mlocate job in /etc/cron.daily which runs updatedb daily.
    – mfisch
    Nov 11, 2012 at 2:20
  • 2
    Just 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: unix.stackexchange.com/questions/26188/… May 12, 2014 at 4:02
  • You probably want to run sudo updatedb after installing mlocate, since the search database needs to be optimized for first time use. Apr 10, 2016 at 20:48
  • 1
    If you're on CentOS/RHEL/Amazon Linux, use sudo yum install mlocate to install it. Also the same, run sudo updatedb to initialize the database for the first time.
    – ADTC
    May 6, 2018 at 0:42
  • 1
    Warning: At least on pop_os! 22.04 mlocate is a transitional dummy package to plocate, which have some advantages but have fewer features (like --transliterate) Nov 22, 2022 at 22:57
1
sudo apt install plocate

Use this to install locate command in 22.04

plocate is better than mlocate

2
  • Thanks 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, 2023 at 23:38
  • 1
    I have added the link
    – Deepak
    Aug 15, 2023 at 2:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .