Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report