Linux系统基础之locate命令

Posted 江湖有缘

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux系统基础之locate命令相关的知识,希望对你有一定的参考价值。

Linux系统基础之locate命令

一、locate命令介绍

Linux locate命令用于查找符合条件的文档,他会去保存文档和目录名称的数据库内,查找合乎范本样式条件的文档或目录。

二、locate的特点

1.locate基于数据库的查询,速度很快,但不是实时的查询。
2.locate是模糊查询
3.需要对文件的目录有rx的权限

三、locate的语法

-b, --basename -- 仅匹配路径名的基本名称
-c, --count -- 只输出找到的数量
-d, --database DBPATH -- 使用 DBPATH 指定的数据库,而不是默认数据库 /var/lib/mlocate/mlocate.db
-e, --existing -- 仅打印当前现有文件的条目
-1 -- 如果 是 1.则启动安全模式。在安全模式下,使用者不会看到权限无法看到 的档案。这会始速度减慢,因为 locate 必须至实际的档案系统中取得档案的 权限资料。
-0, --null -- 在输出上带有NUL的单独条目
-S, --statistics -- 不搜索条目,打印有关每个数据库的统计信息
-q -- 安静模式,不会显示任何错误讯息。
-P, --nofollow, -H -- 检查文件存在时不要遵循尾随的符号链接
-l, --limit, -n LIMIT -- 将输出(或计数)限制为LIMIT个条目
-n -- 至多显示 n个输出。
-m, --mmap -- 被忽略,为了向后兼容
-r, --regexp REGEXP -- 使用基本正则表达式
--regex -- 使用扩展正则表达式
-q, --quiet -- 安静模式,不会显示任何错误讯息
-s, --stdio -- 被忽略,为了向后兼容
-o -- 指定资料库存的名称。
-h, --help -- 显示帮助
-i, --ignore-case -- 忽略大小写
-V, --version -- 显示版本信息

四、locate的日常使用

1.查询passwd

[root@192 ~]# locate passwd -n 5
/etc/passwd
/etc/passwd-
/etc/pam.d/passwd
/etc/security/opasswd
/usr/bin/gpasswd

2.忽略大小写查询

[root@192 ~]# locate -i CONF -n 5
/ansible/roles/webserver/files/httpd.conf
/boot/config-3.10.0-957.el7.x86_64
/boot/grub2/i386-pc/configfile.mod
/etc/GeoIP.conf
/etc/GeoIP.conf.default

3.更新本地数据库

updatedb
[root@192 ~]# updatedb -V
updatedb (mlocate) 0.26
Copyright (C) 2007 Red Hat, Inc. All rights reserved.
This software is distributed under the GPL v.2.

This program is provided with NO WARRANTY, to the extent permitted by law.

4.打印系统数据库的信息

root@192 ~]# locate  -S
Database /var/lib/mlocate/mlocate.db:
	13,857 directories
	189,679 files
	11,268,161 bytes in file names
	4,331,363 bytes used to store database

以上是关于Linux系统基础之locate命令的主要内容,如果未能解决你的问题,请参考以下文章

Linux文件查找命令之locate与find

Linux之locate命令

Linux命令之locate命令

Linux之locate命令

linux基础之文件查找

Linux命令之查找文件locate