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

The Geek Diary

CONCEPTS | BASICS | HOWTO

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • Linux Services
    • VCS
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
    • Data Guard
  • DevOps
    • Docker
    • Shell Scripting
  • Interview Questions
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

The locate Command in Linux

By admin

Local 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 Remove a Dead Mulitpath Device without Reboot in CentOS/RHEL
  2. Error “530: permission denied” when user logs in to vsftpd server via ftp
  3. How to Rebuild the “initramfs” with Multipath in CentOS/RHEL 6 and 7
  4. “sudo: /etc/sudoers is world writable” – How to correct the permissions of sudoers file
  5. “Metadata File Does Not Match Checksum” Issue When Yum Installs or Updates Package
  6. CentOS / RHEL 7 : How to Enable the Old ethX Style Network Interfaces Names
  7. CentOS / RHEL 7 : How to set date, time / NTP and timezone using timedatectl
  8. Unable to ssh to server after integration into Active Directory (AD) Domain [CentOS/RHEL 7]
  9. Creating and Removing Files and Directories Under Linux
  10. pvcreate Fails With Error: “Device /dev/mapper/mpatha Not Found (or Ignored By Filtering).”

You May Also Like

Primary Sidebar

Recent Posts

  • How to Disable IPv6 on Ubuntu 18.04 Bionic Beaver Linux
  • How to Capture More Logs in /var/log/dmesg for CentOS/RHEL
  • Unable to Start RDMA Services on CentOS/RHEL 7
  • How to rename a KVM VM with virsh
  • Archives
  • Contact Us
  • Copyright

© 2021 · The Geek Diary