Get the App
SLTechnology News&Howtos  ›  Servers  › 

Use the locate command of linux to quickly find files or directories

Shulou Source: shulou.com Published: 2022-06-02 12:42:35 10月04日 Update

Do not know how to use linux's locate command to quickly find files or directories? In fact, it is not difficult to solve this problem. Let the editor take you to learn how to solve it. I hope you will gain a lot after reading this article.

The locate command is actually another way of writing find-name, but much faster than the latter, because it searches a database / var/lib/locatedb instead of a specific directory, and it's worth noting that it varies from version to version. Some versions are located in / var/lib/mlocate/mlocatedb, and others are in / var/lib/slocate/slocate.db, and this database contains all the local file information.

The Linux system automatically creates this database and automatically updates it once a day, so you can't find the most recently changed files using the locate command. To avoid this, you can manually update the database using the updatedb command before using locate.

Syntax format: locate [parameters] [file]

Common parameters:

-d or-- database= specify the directory where the database is located-- help display help-- version displays version information

Reference example

Search for all files that begin with sh in the / etc directory:

[root@linuxcool ~] # locate / etc/sh

/ etc/shadow

/ etc/shadow-

/ etc/shells

Search for files that begin with k in the / etc directory:

[root@linuxcool ~] # locate / etc/k

/ etc/kdump.conf

/ etc/kernel

/ etc/krb5.conf

/ etc/krb5.conf.d

/ etc/ksmtuned.conf

/ etc/kernel/postinst.d

/ etc/kernel/postinst.d/51-dracut-rescue-postinst.sh

Find all files related to pwd:

[root@linuxcool ~] # locate pwd

/ boot/extlinux/pwd.c32

/ etc/.pwd.lock

/ usr/bin/pwd

/ usr/bin/pwdx

/ usr/include/pwd.h

Thank you for reading this article carefully. I hope the editor will share and use linux's locate command to quickly find the contents of files or directories. At the same time, I also hope that you will support us, pay attention to the industry information channel, and find out if you encounter problems. Detailed solutions are waiting for you to learn!

Tags: Files directories commands data databases searches versions different information parameters beginning articles questions learning help updates location content writing Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Redmi MySQL macOS MariaDB