• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

The locate Command in Linux

by admin

locate command

locate is considered low-impacting in terms of system resource consumption, because it does not search the file system in real time. Instead, locate searches through a database which is updated at idle hours (usually at night). This approach provides very fast searching, but results may not reflect recently added or deleted files.

The basic syntax of the locate command is:

# locate [options] search_string

The following example shows how to use locate to find a specific file by filename:

$ locate file1
/var/tmp/file1.txt

There are multiple implementations of the locate command. All offer similar functionality, but have implemented different features.

  • locate: This is the original locate that is currently maintained by the GNU foundation. The locate command is included in the mlocate package available from the GNU foundation.
  • slocate: Secure locate (slocate) is secure in that it stores files’ permissions in its database, and therefore will not locate files for users who do not have the right to see them.

Building the locate Database

On a newly installed system that hasn’t run through the night, you’ll need to login as root and run the following command to create the database:

# /etc/cron.daily/mlocate.cron

locate Packages

In order to use the locate command the proper RPM package must be installed. To find which package provides the locate command use the command below:

# yum whatprovides locate
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.lga7.us.voxel.net
 * epel: mirror.cogentco.com
 * extras: mirror.genesisadaptive.com
 * nux-dextop: li.nux.ro
 * updates: mirrors.gigenet.com
epel/x86_64/filelists_db                        | 9.9 MB  00:00:00     
mlocate-0.26-6.el7.x86_64 : An utility for finding files by name
Repo        : base
Matched from:
Filename    : /usr/bin/locate

As shown above mlocate package provides the locate command.

What’s the difference between locate and find command in Linux

Filed Under: Linux

Some more articles you might also be interested in …

  1. ceph Command Examples in Linux
  2. collectd Command Examples
  3. a2enconf Command Examples in Linux
  4. aa-complain: command not found
  5. How to use FTP under Linux to transfer files
  6. dotnet publish: Publish a .NET application and its dependencies to a directory for deployment to a hosting system
  7. sstat Command Examples in Linux
  8. rm: command not found
  9. viewnior Command Examples in Linux
  10. How to change the PATH variable in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright