Locate command ... a search engine built into each distro


One of the commands that I use a lot is precisely this: locate

Every desktop environment has a file browser, in KDE we KFind, there are alternatives for other environments such as CatFish, etc. But generally I am very busy and many times it is more comfortable for me to use the same terminal that I have open, and through this make a search for something, than to have to open another application (search engine, etc.) and put the search parameter, and then search ...

That's why I use a lot locate, a command that shows us in literally a matter of seconds all the results that match our search.

The main advantage that locate It offers any option over another, it is instantaneous, it shows what we are looking for literally at the moment. how is this possible? simple ... it happens that in our system we have an index of everything (or almost everything) that we have stored in it, and locate what it does is search that index for what we indicate.

Explained in a simpler way. When we search for something as we commonly do, at that moment the system is searched (folder by folder…. File by file) what we said, right? ... well, imagine you have a list of all the folders and files you have on your computer, and just look at that list where X files are. Isn't it simpler to search a text file of a few MBs, than to search TOOOOOOODO your hard disk? 😀

But hey… let's get down to business hehe.

Let's say for example that we want to find all files .ODT we have, we open a terminal and in it we write the following and press [Enter]:

locate -e *.odt

El -e I put it to specify that it looks for files that still exist, since the index with which it works locate Many times it contains information about files that were deleted, and it doesn't make much sense to show us files that no longer exist, right? 🙂

Anyway, now I will search my laptop for everything that contains the name «so»… We put the following:

locate -e asa

You notice the speed right? … Impressive 🙂

As a curious fact, the database (index) used by locate is: /var/lib/mlocate/mlocate.db

And well this is it, try the command and tell me that such haha.


The content of the article adheres to our principles of editorial ethics. To report an error click here!.

20 comments, leave yours

Leave a Comment

Your email address will not be published. Required fields are marked with *



  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   dhunter said

    A tip, with the updatedb command this database is updated.

    1.    sieg84 said

      I was just going to ask how that database is updated.

    2.    KZKG ^ Gaara said

      Great 😀… another little thing that I learn hehehehehe.
      Hey, a detail ... wouldn't you like to blog directly? I know the problems with the connection and such, precisely for that reason it could be configured to publish by email or something like that 😉

  2.   rogertux said

    Very good. In my case, the database is not in that directory or with that name, but with a "locate locate" everything is fixed: / var / lib / locatedb

    1.    KZKG ^ Gaara said

      HAHAHA locate locate … Fuck great haha ​​😀

  3.   davidlg said

    he tells me

    bash: locate: command not found

    1.    proper said

      treats as root, although it shouldn't be.

    2.    rogertux said

      You may have to install it.

    3.    KZKG ^ Gaara said

      Try with / usr / bin / locate asd Let's see what it tells you 🙂… if it doesn't work for you, check that you have the mlocate package installed, which is strange… because I have used Ubuntu, Debian and Arch and this command is installed by default in all of them.

      1.    davidlg said

        after reinstalling

        [david @ arch ~] $ usr / bin / locate asd
        bash: usr / bin / locate: The file or directory does not exist
        [david @ arch ~] $ locate locate
        locate: could not perform stat () `/var/lib/mlocate/mlocate.db ': The file or directory does not exist

  4.   Rayonant said

    Excellent command, I did not know him, and if the speed is impressive! and a man locate already explain the rest to me, thank you very much

    1.    KZKG ^ Gaara said

      You're welcome, a pleasure 😀

  5.   taregon said

    Hmm… better than find? a speed test should be done oO

    In my case I could do the same searches, but like this:

    $ find / home / user -iname "* .odt"
    find / home / user -iname "* handle *"

    If I wanted to find certain files and know their size:

    $ find -iname "* .iso" -exec du -h {} \;

    Although, in fact, even with ls I search within the current directory, that is, if I know where the file may be located:

    omega @ mega-laptop ~ / Images $ ls * .png

    1.    taregon said

      Oops, excuse me, I was denied more than necessary 😐

      1.    KZKG ^ Gaara said

        Nah don't worry, if you want I'll fix it 🙂

    2.    KZKG ^ Gaara said

      Find does the search the moment you execute it, while locate has already done the search and generated a list some time ago ... and when you execute it, what it does is look for what you set as a parameter in a file of few MBs or KBs 😀

      1.    taregon said

        Ah, thanks for the 😉 comparison. Hehe, a little late in answering but work has me busy 🙂

        Saying it like this reminds me of the windows "index server" when speeding up searches.

        1.    KZKG ^ Gaara said

          This reminds me of the KDE semantic desktop searches (Nepomuk specifically) 😀

          1.    taregon said

            Interesting, I'm more of the gnome type so I didn't know about kde: O

  6.   Marta said

    somebody help me..i tried to update and i get updatedb: cannot open temp file for `/var/lib/mlocate/mlocate.db '
    On the other hand I have used the locate locate (I loved it) and if I locate the file above ...
    What would they do in my place? please in a language for beginners ... and I hope this keeps updating