How to install locate command in Linux

In this article, we will see how to install locate command in Linux.

The locate is a command line utility for finding files by name in Linux, just like find command. However, it works more efficiently compared to its counterpart; it uses one or more databases populated by the updatedb program and prints file names matching at least one of the patterns (a user provides) to standard output.

By default, locate command is not installed. When we tried to run locate command from Linux terminal, we will receive below error.

Command 'locate' not found, but can be installed with: sudo apt install mlocate

Install locate command in Linux

Run the below command on your terminal.

sudo apt-get install mlocate

Output of above command is:

[sudo] password for r2schools: Reading package lists... Done Building dependency tree Reading state information... Done Suggested packages: nocache The following NEW packages will be installed: mlocate 0 upgraded, 1 newly installed, 0 to remove and 146 not upgraded. Need to get 50.1 kB of archives. After this operation, 258 kB of additional disk space will be used. Get:1 http://us.archive.ubuntu.com/ubuntu focal/main amd64 mlocate amd64 0.26-3u buntu3 [50.1 kB] Fetched 50.1 kB in 1s (69.4 kB/s) Selecting previously unselected package mlocate. (Reading database ... 196023 files and directories currently installed.) Preparing to unpack .../mlocate_0.26-3ubuntu3_amd64.deb ... Unpacking mlocate (0.26-3ubuntu3) ... Setting up mlocate (0.26-3ubuntu3) ... update-alternatives: using /usr/bin/mlocate to provide /usr/bin/locate (locate) in auto mode Adding group `mlocate' (GID 135) ... Done. Initializing mlocate database; this may take some time... done Processing triggers for man-db (2.9.1-1) ...

So, now you can find files or folders using Linux locate command.