linux中 locate命令

 

locate特定:

001:速度快

002:查找依赖于/var/lib/mlocate/mlocate.db

为了时效性查找,在使用locate命令之前可以先更新库: updatedb

 

示例:

 

1、locate + file

复制代码
root@DESKTOP-1N42TVH:/home/test# locate a.txt           ## 查找系统中所有包含a.txt的文件
root@DESKTOP-1N42TVH:/home/test# locate a.txt | head
/home/test/a.txt
/mnt/c/Program Files/Windows NT/TableTextService/TableTextServiceTigrinya.txt
/mnt/c/Program Files (x86)/Internet Download Manager/Languages/tips_fa.txt
/mnt/c/Program Files (x86)/Microsoft Office/root/Office16/2052/AccessRuntime2019_eula.txt
/mnt/c/Program Files (x86)/Microsoft Office/root/Office16/2052/AccessRuntime2021_eula.txt
/mnt/c/Program Files (x86)/Microsoft Office/root/Office16/2052/AccessRuntime_eula.txt
/mnt/c/Program Files (x86)/Microsoft Office/root/Office16/2052/Client2019_eula.txt
/mnt/c/Program Files (x86)/Microsoft Office/root/Office16/2052/Client2021_eula.txt
/mnt/c/Program Files (x86)/Microsoft Office/root/Office16/2052/ClientARMRefer2019_eula.txt
/mnt/c/Program Files (x86)/Microsoft Office/root/Office16/2052/ClientARMRefer_eula.txt
复制代码

 

2、限定查找到的文件的数目

root@DESKTOP-1N42TVH:/home/test# locate -n 3 a.txt         ## 限制输出3个
/home/test/a.txt
/mnt/c/Program Files/Windows NT/TableTextService/TableTextServiceTigrinya.txt
/mnt/c/Program Files (x86)/Internet Download Manager/Languages/tips_fa.txt

 

3、 查找目录中以sh开头的文件

root@DESKTOP-1N42TVH:/home/test# locate /bin/sh      ## 查找目录中以sh开头的文件
/mnt/d/programs/Git/bin/sh.exe
/mnt/d/programs/Git/usr/bin/sh.exe
/mnt/d/programs/Git/usr/bin/sha1sum.exe
/mnt/d/programs/Git/usr/bin/sha224sum.exe

 

4、-i忽略大小写查找

root@DESKTOP-1N42TVH:/home/test# ls
a.txt  xYAbzM.txt  xyabzm.txt
root@DESKTOP-1N42TVH:/home/test# locate xyabzm.txt
/home/test/xyabzm.txt
root@DESKTOP-1N42TVH:/home/test# locate xyabzm.txt -i      ## -i忽略大小写进行查找
/home/test/xYAbzM.txt
/home/test/xyabzm.txt

 

5、-c选项统计查找到的数量

复制代码
root@DESKTOP-1N42TVH:/home/test# ls
a.txt  xYAbzM.txt  xyabzm.txt
root@DESKTOP-1N42TVH:/home/test# locate xyabzm.txt
/home/test/xyabzm.txt
root@DESKTOP-1N42TVH:/home/test# locate -c xyabzm.txt
1
root@DESKTOP-1N42TVH:/home/test# locate -i xyabzm.txt
/home/test/xYAbzM.txt
/home/test/xyabzm.txt
root@DESKTOP-1N42TVH:/home/test# locate -c -i xyabzm.txt    ## -i表示忽略大小写, -c表示统计数目
2
复制代码

 

6、-r选项用于正则表达式

root@DESKTOP-1N42TVH:/home/test# ls
a.txt  xYAbzM.txt  xyabzm.txt
root@DESKTOP-1N42TVH:/home/test# locate -r xy*    ## 查找以xy开头的行
/home/test/xyabzm.txt
root@DESKTOP-1N42TVH:/home/test# locate -r xY*    ## 查考以xY开头的行
/home/test/xYAbzM.txt
root@DESKTOP-1N42TVH:/home/test# locate -r zm.txt$   ## 查考以zm.txt结尾的行
/home/test/xyabzm.txt

 

参考:https://www.jb51.net/article/180941.htm

 

posted @   小鲨鱼2018  阅读(405)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
历史上的今天:
2021-04-30 c语言 5-11
2021-04-30 c语言 5-10 求4行3列矩阵和3行4列矩阵的乘积。各构成元素的值从键盘输入。
点击右上角即可分享
微信分享提示