
一、locate命令介绍
Linux locate命令用于查找符合条件的文档,他会去保存文档和目录名称的数据库内,查找合乎范本样式条件的文档或目录。
二、locate的特点
1.locate基于数据库的查询,速度很快,但不是实时的查询。 2.locate是模糊查询 3.需要对文件的目录有rx的权限
三、locate的语法
1-b, --basename -- 仅匹配路径名的基本名称 2-c, --count -- 只输出找到的数量 3-d, --database DBPATH -- 使用 DBPATH 指定的数据库,而不是默认数据库 /var/lib/mlocate/mlocate.db 4-e, --existing -- 仅打印当前现有文件的条目 5-1 -- 如果 是 1.则启动安全模式。在安全模式下,使用者不会看到权限无法看到 的档案。这会始速度减慢,因为 locate 必须至实际的档案系统中取得档案的 权限资料。 6-0, --null -- 在输出上带有NUL的单独条目 7-S, --statistics -- 不搜索条目,打印有关每个数据库的统计信息 8-q -- 安静模式,不会显示任何错误讯息。 9-P, --nofollow, -H -- 检查文件存在时不要遵循尾随的符号链接 10-l, --limit, -n LIMIT -- 将输出(或计数)限制为LIMIT个条目 11-n -- 至多显示 n个输出。 12-m, --mmap -- 被忽略,为了向后兼容 13-r, --regexp REGEXP -- 使用基本正则表达式 14--regex -- 使用扩展正则表达式 15-q, --quiet -- 安静模式,不会显示任何错误讯息 16-s, --stdio -- 被忽略,为了向后兼容 17-o -- 指定资料库存的名称。 18-h, --help -- 显示帮助 19-i, --ignore-case -- 忽略大小写 20-V, --version -- 显示版本信息
四、locate的日常使用
1.查询passwd
1[root@192 ~]# locate passwd -n 5 2/etc/passwd 3/etc/passwd- 4/etc/pam.d/passwd 5/etc/security/opasswd 6/usr/bin/gpasswd 7
2.忽略大小写查询
1[root@192 ~]# locate -i CONF -n 5 2/ansible/roles/webserver/files/httpd.conf 3/boot/config-3.10.0-957.el7.x86_64 4/boot/grub2/i386-pc/configfile.mod 5/etc/GeoIP.conf 6/etc/GeoIP.conf.default
3.更新本地数据库
1updatedb 2[root@192 ~]# updatedb -V 3updatedb (mlocate) 0.26 4Copyright (C) 2007 Red Hat, Inc. All rights reserved. 5This software is distributed under the GPL v.2. 6 7This program is provided with NO WARRANTY, to the extent permitted by law. 8
4.打印系统数据库的信息
1root@192 ~]# locate -S 2Database /var/lib/mlocate/mlocate.db: 3 13,857 directories 4 189,679 files 5 11,268,161 bytes in file names 6 4,331,363 bytes used to store database 7
