• Contact
  • Contact Us
  • Disclamer
  • Home 1
  • Home 2
  • Home 3
  • Privacy Policy
Saturday, June 14, 2025
How VPS - How to use/setup VPS
  • Login
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Operating System Linux

10 Useful ‘locate’ Command Practical Examples for Linux Newbies

How VPS by How VPS
November 2, 2018
in Linux, Operating System
0
0
SHARES
39
VIEWS
Share on FacebookShare on Twitter

Contents

  1. 1. Using locate Command
  2. 2. Limit Search Queries to a Specific Number
  3. 3. Display The Number of Matching Entries
  4. 4. Ignore Case Sensitive Locate Outputs
  5. 5. Refresh mlocate Database
  6. 6. Display Only Files Present in Your System
  7. 7. Separate Output Entries Without New Line
  8. 8. Review Your Locate Database
  9. 9. Suppress Error Messages in Locate
  10. 10. Choose a Different mlocate Location

One of most obnoxious experiences that most new users of the Linux platform usually face is the inability to find the simplest and yet more effective means of looking up files on their system.

Linux, like almost any other operating system, utilizes several mechanisms to answer search queries for users. Two of the most popular file searching utilities accessible to users are called find and locate.

Now, it is important to note that both search processes work extremely well but nonetheless, the center of this article will be more on the locate utility, which is the more convenient of the two as it uses more efficient ways to quickly process queries inputted by the users.

The locate utility works better and faster than it’s find counterpart because instead of searching the file system when a file search is initiated – Something find does – locate would look through a database. This database contains bits and parts of files and their corresponding paths on your system.

Here are ten simple locate commands to set you up in becoming more productive with your Linux machine.

1. Using locate Command

Firing locate command to look for a file is pretty easy and straightforward. All you need to do is type:

$ locate LAMP-Setup.odt

/home/tecmint/LAMP-Setup.odt
/home/tecmint/TecMint.com/LAMP-Setup.odt

2. Limit Search Queries to a Specific Number

You can limit your search returns to a required number to avoid redundancy with your search results using the -n command.

For example, if you want just 20 results from your queries, you can type the following command:

$ locate "*.html" -n 20

/home/tecmint/.config/google-chrome/Default/Extensions/aapocclcgogkmnckokdopfmhonfmgoek/0.9_0/main.html
/home/tecmint/.config/google-chrome/Default/Extensions/aohghmighlieiainnegkcijnfilokake/0.9_0/main.html
/home/tecmint/.config/google-chrome/Default/Extensions/felcaaldnbdncclmgdcncolpebgiejap/1.1_0/main.html
/home/tecmint/.config/google-chrome/Default/Extensions/kbfnbcaeplbcioakkpcpgfkobkghlhen/14.752.848_0/forge.html
/home/tecmint/.config/google-chrome/Default/Extensions/kbfnbcaeplbcioakkpcpgfkobkghlhen/14.752.848_0/src/popup.html
/home/tecmint/.config/google-chrome/Default/Extensions/nlipoenfbbikpbjkfpfillcgkoblgpmj/3.9.16_0/additional-feature.html
/home/tecmint/.config/google-chrome/Default/Extensions/nlipoenfbbikpbjkfpfillcgkoblgpmj/3.9.16_0/background.html
/home/tecmint/.config/google-chrome/Default/Extensions/nlipoenfbbikpbjkfpfillcgkoblgpmj/3.9.16_0/edit.html
/home/tecmint/.config/google-chrome/Default/Extensions/nlipoenfbbikpbjkfpfillcgkoblgpmj/3.9.16_0/help.html
/home/tecmint/.config/google-chrome/Default/Extensions/nlipoenfbbikpbjkfpfillcgkoblgpmj/3.9.16_0/options.html
/home/tecmint/.config/google-chrome/Default/Extensions/nlipoenfbbikpbjkfpfillcgkoblgpmj/3.9.16_0/popup.html
/home/tecmint/.config/google-chrome/Default/Extensions/nlipoenfbbikpbjkfpfillcgkoblgpmj/3.9.16_0/purchase.html
/home/tecmint/.config/google-chrome/Default/Extensions/nlipoenfbbikpbjkfpfillcgkoblgpmj/3.9.16_0/upload.html
/home/tecmint/.config/google-chrome/Default/Extensions/nlipoenfbbikpbjkfpfillcgkoblgpmj/3.9.16_0/oauth2/oauth2.html
/home/tecmint/.config/google-chrome/Default/Extensions/nmmhkkegccagdldgiimedpiccmgmieda/1.0.0.2_0/html/craw_window.html
/home/tecmint/.config/google-chrome/Default/Extensions/pkedcjkdefgpdelpbcmbmeomcjbeemfm/5516.1005.0.3_0/cast_route_details.html
/home/tecmint/.config/google-chrome/Default/Extensions/pkedcjkdefgpdelpbcmbmeomcjbeemfm/5516.1005.0.3_0/feedback.html
/home/tecmint/.config/google-chrome/Default/Extensions/pkedcjkdefgpdelpbcmbmeomcjbeemfm/5516.1005.0.3_0/cast_setup/devices.html
/home/tecmint/.config/google-chrome/Default/Extensions/pkedcjkdefgpdelpbcmbmeomcjbeemfm/5516.1005.0.3_0/cast_setup/index.html
/home/tecmint/.config/google-chrome/Default/Extensions/pkedcjkdefgpdelpbcmbmeomcjbeemfm/5516.1005.0.3_0/cast_setup/offers.html

The results will show the first 20 files that end with .html.

3. Display The Number of Matching Entries

If you want to display the count of all matching entries of file “tecmint“, use the locate -c command.

$ locate -c [tecmint]*

1550

4. Ignore Case Sensitive Locate Outputs

By default, locate is configured to process queries in a case sensitive manner meaning TEXT.TXT will point you to a different result than text.txt.

To have locate command ignore case sensitivity and show results for both uppercase and lowercase queries, input commands with the -i option.

$ locate -i *text.txt*

/home/tecmint/TEXT.txt
/home/tecmint/text.txt

5. Refresh mlocate Database

Since locate command relies on a database called mlocate. The said database needs to be updated regularly for the command utility to work
efficiently.

To update the mlocate database, you use a utility called updatedb. It should be noted that you will need superuser privileges for this to work properly, is it needs to be executed as root or sudo privileges.

$ sudo updatedb

6. Display Only Files Present in Your System

When you have an updated mlocate database**, locate command still produces results of files whose physical copies are deleted from your system.

To avoid seeing results of files not present in your machine at the time of punching in the command, you will need to use the locate-e command. The process searches your system to verify the existence of the file you’re looking for even if it is still present in your mlocate.db.

$ locate -i -e *text.txt*

/home/tecmint/text.txt

7. Separate Output Entries Without New Line

locate command’s default separator is the newline (//n) character. But if you prefer to use a different separator like the ASCII NUL, you can do so using the -0 command line option.

$ locate -i -0 *text.txt*

/home/tecmint/TEXT.txt/home/tecmint/text.txt

8. Review Your Locate Database

If you’re in doubt as to the current status of your mlocate.db, you can easily view the locate database statistics by using the -S command.

$ locate -S

Database /var/lib/mlocate/mlocate.db:
	32,246 directories
	4,18,850 files
	2,92,36,692 bytes in file names
	1,13,64,319 bytes used to store database

9. Suppress Error Messages in Locate

Constantly trying to access your locate database does sometimes yield unnecessary error messages stating that you do not have the required privileges to have root access to the mlocate.db, because you’re only a normal user and not the required Superuser.

To completely do away with these message, use the -q command.

$ locate "/*.dat" -q*

10. Choose a Different mlocate Location

If you’re inputting queries looking for results not present in the default mlocate database and want answers from a different mlocate.db located somewhere else in your system, you can point the locate command to a different mlocate database at a different part of your system with the -d command.

$ locate -d <new db path> <filename>

locate command might seem like one of those utilities that does everything you asked it to do without much of a hustle but in truth, in order for the process to keep its efficiency, the mlocate.db needs to be fed with information every now and then. Failure to do so might render the program a bit useless.

Source: tecmint.com

Tags: Linux Commandslinux guidelinux vps setup guide
Previous Post

How to Configure Cloudflare Security Options

Next Post

How to Find Out List of All Open Ports in Linux

Next Post

How to Find Out List of All Open Ports in Linux

Leave a Reply Cancel reply

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

No Result
View All Result

Recent Post

Install Imagemagick on CentOS
CentOS

Install Imagemagick on CentOS

by How VPS
June 28, 2023
0

This is how I installed Imagemagick on a vanilla CentOS server Start off by installing the prerequisites yum install php-pear...

Read more
how to Check phpinfo

How to Check phpinfo of Hosting or VPS?

June 28, 2023
Failed to download metadata for repo 'appstream' on Centos 8

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020

Recent News

  • Install Imagemagick on CentOS
  • How to Check phpinfo of Hosting or VPS?
  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

Category

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel
  • About
  • Advertise
  • Careers
  • Contact

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In