【Linux】locate指令(定位目标位置)biubiu~~

【Linux】locate指令(定位目标位置)biubiu~~

Scroll Down

在排查问题时经常会查找某些软件的配置文件。修改配置文件啥的。

我们平常能记住肯定是直接前往目标文件路径。记不住用find,where啥的来定位。

今天在排查问题时发现了一个好用的指定 locate

安装

[root@iZbp18nyz28va2zwadft2qZ conf]# yum  -y install mlocate
Resolving Dependencies
--> Running transaction check
---> Package mlocate.x86_64 0:0.26-8.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================
 Package                 Arch                   Version                    Repository            Size
======================================================================================================
Installing:
 mlocate                 x86_64                 0.26-8.el7                 base                 113 k

Transaction Summary
======================================================================================================
Install  1 Package

Total download size: 113 k
Installed size: 379 k
Downloading packages:
mlocate-0.26-8.el7.x86_64.rpm                                                  | 113 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mlocate-0.26-8.el7.x86_64                                                          1/1 
  Verifying  : mlocate-0.26-8.el7.x86_64                                                          1/1 

Installed:
  mlocate.x86_64 0:0.26-8.el7                                                                         

Complete!
[root@iZbp18nyz28va2zwadft2qZ conf]# 
[root@iZbp18nyz28va2zwadft2qZ conf]# 
[root@iZbp18nyz28va2zwadft2qZ conf]# locate my.cnf
locate: can not stat () `/var/lib/mlocate/mlocate.db': No such file or directory
[root@iZbp18nyz28va2zwadft2qZ conf]# 
[root@iZbp18nyz28va2zwadft2qZ conf]# updatedb

演示1(定位系统中my.cnf文件的路径)

[root@iZbp18nyz28va2zwadft2qZ conf]# locate my.cnf
/etc/my.cnf
/etc/my.cnf.d
/var/lib/docker/overlay2/79a292dd8ea4346c6a34f88bb9b1a2de9126956d06003f75d534863f7ab1dff3/merged/etc/alternatives/my.cnf
/var/lib/docker/overlay2/79a292dd8ea4346c6a34f88bb9b1a2de9126956d06003f75d534863f7ab1dff3/merged/etc/mysql/my.cnf
/var/lib/docker/overlay2/79a292dd8ea4346c6a34f88bb9b1a2de9126956d06003f75d534863f7ab1dff3/merged/etc/mysql/my.cnf.fallback
/var/lib/docker/overlay2/79a292dd8ea4346c6a34f88bb9b1a2de9126956d06003f75d534863f7ab1dff3/merged/var/lib/dpkg/alternatives/my.cnf
/var/lib/docker/overlay2/c5b84c7a5d87dc9e90872f7af95a60fbf702b5bb97329b0794076d881a728914/diff/etc/alternatives/my.cnf
/var/lib/docker/overlay2/c5b84c7a5d87dc9e90872f7af95a60fbf702b5bb97329b0794076d881a728914/diff/etc/mysql/my.cnf
/var/lib/docker/overlay2/c5b84c7a5d87dc9e90872f7af95a60fbf702b5bb97329b0794076d881a728914/diff/etc/mysql/my.cnf.fallback
/var/lib/docker/overlay2/c5b84c7a5d87dc9e90872f7af95a60fbf702b5bb97329b0794076d881a728914/diff/var/lib/dpkg/alternatives/my.cnf

演示2(定位系统中后缀为log的文件的路径)

[root@iZbp18nyz28va2zwadft2qZ conf]# locate *.log
/opt/apache-activemq-5.15.12/data/activemq.log
/opt/apache-activemq-5.15.12/data/audit.log
/opt/apache-activemq-5.15.12/data/kahadb/db-1.log
/opt/dubbo-tomcat/bin/dubbo-governance.log
/opt/dubbo-tomcat/logs/catalina.2019-11-26.log
/opt/dubbo-tomcat/logs/catalina.2019-11-27.log
/opt/dubbo-tomcat/logs/catalina.2019-11-28.log
/opt/dubbo-tomcat/logs/catalina.2019-11-30.log
/opt/dubbo-tomcat/logs/catalina.2019-12-01.log
/opt/dubbo-tomcat/logs/catalina.2019-12-03.log
/opt/dubbo-tomcat/logs/catalina.2019-12-04.log
/opt/dubbo-tomcat/logs/catalina.2019-12-05.log
/opt/dubbo-tomcat/logs/catalina.2019-12-08.log
/opt/dubbo-tomcat/logs/catalina.2019-12-09.log
/opt/dubbo-tomcat/logs/catalina.2019-12-11.log
/opt/dubbo-tomcat/logs/catalina.2019-12-12.log
/opt/dubbo-tomcat/logs/catalina.2019-12-14.log
/opt/dubbo-tomcat/logs/catalina.2019-12-16.log
/opt/dubbo-tomcat/logs/catalina.2019-12-18.log
/opt/dubbo-tomcat/logs/catalina.2019-12-20.log
/opt/dubbo-tomcat/logs/catalina.2019-12-22.log
/opt/dubbo-tomcat/logs/catalina.2019-12-24.log
/opt/dubbo-tomcat/logs/catalina.2020-01-08.log
/opt/dubbo-tomcat/logs/catalina.2020-01-09.log
/opt/dubbo-tomcat/logs/catalina.2020-01-10.log
/opt/dubbo-tomcat/logs/catalina.2020-01-12.log
/opt/dubbo-tomcat/logs/catalina.2020-01-13.log
/opt/dubbo-tomcat/logs/catalina.2020-01-14.log
/opt/dubbo-tomcat/logs/catalina.2020-01-16.log
/opt/dubbo-tomcat/logs/catalina.2020-01-18.log
/opt/dubbo-tomcat/logs/catalina.2020-01-19.log
/opt/dubbo-tomcat/logs/catalina.2020-01-20.log
/opt/dubbo-tomcat/logs/catalina.2020-01-21.log
/opt/dubbo-tomcat/logs/catalina.2020-01-22.log
/opt/dubbo-tomcat/logs/catalina.2020-01-24.log
/opt/dubbo-tomcat/logs/catalina.2020-01-25.log
/opt/dubbo-tomcat/logs/catalina.2020-01-26.log
/opt/dubbo-tomcat/logs/catalina.2020-01-28.log
/opt/dubbo-tomcat/logs/catalina.2020-01-30.log
/opt/dubbo-tomcat/logs/catalina.2020-01-31.log
/opt/dubbo-tomcat/logs/catalina.2020-02-02.log
/opt/dubbo-tomcat/logs/catalina.2020-02-04.log
/opt/dubbo-tomcat/logs/catalina.2020-02-05.log
/opt/dubbo-tomcat/logs/catalina.2020-02-06.log
/opt/dubbo-tomcat/logs/catalina.2020-02-08.log
/opt/dubbo-tomcat/logs/catalina.2020-02-10.log
/opt/dubbo-tomcat/logs/catalina.2020-02-12.log
/opt/dubbo-tomcat/logs/catalina.2020-02-13.log
/opt/dubbo-tomcat/logs/catalina.2020-02-16.log
................

so many...省略了。太多了 ^.^

总结

这个locate命令用于你想找一些特定的文件,十分简单方便。

但是当像对寻找目标模糊匹配时可能结果会有太多。不太适用。

根据实际需要使用。