locate帮助
-b, --basename 匹配唯一的路径名称的基本文件名
-c, --count 只显示找到条目的号码
-d, --database DBPATH 用 DBPATH 替代默认的数据库(/var/lib/mlocate/mlocate.db)
-e, --existing 只显示当前存在的文件条目
-L, --follow 当文件存在时跟随蔓延的符号链接 (默认)
-h, --help 显示本帮助
-i, --ignore-case 匹配模式时忽略大小写区别
-l, --limit, -n LIMIT 限制为 LIMIT项目的输出 (或 计数)
-m, --mmap 忽略向后兼容性
-P, --nofollow, -H 当检查文件时不跟随蔓延的符号链接
-0, --null 输出时以 NUL 分隔项目
-S, --statistics 不搜索项目,显示有关每个已用数据库的统计信息
-q, --quiet 不报告关于读取数据库的错误消息
-r, --regexp REGEXP 搜索基本正则表达式 REGEXP 来代替模式
--regex 模式是扩展正则表达式
-s, --stdio 忽略向后兼容性
-V, --version 显示版本信息
-w, --wholename 匹配完整路径名 (默认)
为了避免新建的文件或目录搜索不到,常执行updatedb手动更新(默认是一天更新一次)
用法示例:
1.查找和crontab相关的所有文件
locate crontab
2.搜索/usr/bin目录下,所有以z开头的文件,最多显示5个输出
locate -n 5 /usr/bin/z
3.返回现有 .json 文件(已经删除但没有update目录或索引的不统计)
locate -e *.json
locate -e -r 'yml$'
4.在系统中搜索所有 .mp4 与 .png 文件(忽略大小写),并统计数量
locate --regex -i "(\.mp4|\.png)" |wc -l
locate -r 'yml$'
[root@hadoop-senior ~]# locate -r -i "(\.mp4|\.png)" |wc -l
locate: non-option arguments are not allowed with --regexp
0
locate -e -c -l 5 -r 'yml$'
[root@hadoop-senior ~]# mkdir testnewfirname
[root@hadoop-senior ~]# locate testnewfirname
[root@hadoop-senior ~]# updatedb
[root@hadoop-senior ~]# locate testnewfirname
/root/testnewfirname
[root@hadoop-senior ~]# rm -rf testnewfirname/
[root@hadoop-senior ~]# locate testnewfirname
/root/testnewfirname
[root@hadoop-senior ~]# locate -e testnewfirname
[root@hadoop-senior ~]# updatedb
[root@hadoop-senior ~]# locate testnewfirname
[root@hadoop-senior ~]#
[root@hadoop-senior ~]# locate -S
Database /var/lib/mlocate/mlocate.db:
36,417 directories
275,382 files
22,756,085 bytes in file names
8,742,218 bytes used to store database
[root@hadoop-senior ~]# locate -b -r ^mlocate.*db$
/var/lib/mlocate/mlocate.db