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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • 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. How to Configure Device File owner/group with udev rules
  2. hostnamectl: command not found
  3. Unable to Run X Applications Through SSH in Linux
  4. How To Migrate Existing Iptables rules to Nftables In CentOS/RHEL 8
  5. raspistill: command not found
  6. grub2-mkconfig: command not found
  7. Defining System Jobs Using Cron under Linux
  8. How to make ethtool settings persistent across reboots in CentOS / RHEL 6,7
  9. CentOS / RHEL 7 : How to install and configure ftp server (vsftpd)
  10. lspcmcia Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • nixos-rebuild Command Examples in Linux
  • nixos-option: Command Examples in Linux
  • nixos-container : Command Examples in Linux
  • nitrogen Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright