三:linux搜索命令locate

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yuming226/article/details/82810497

locate命令简介

locate命令用来查找文件或目录。locate命令的查找速度要比find快很多,原因在于他们的查找的方式不同。locate搜索的是数据库/var/lib/mlocate/mlocate.db,因此在后台数据库中只需按照文件名搜索,搜索速度更快。然而find进行文件查找时,需要搜索整个磁盘目录,因此查找速度回相对较慢。

linux系统会自动更新mlocate.db数据库,并别每天自动更新一次(不是实时更新的),因此在使用whereis和locate查找文件时,有时会找到已经被删除的数据,或者刚刚建立文件,却无法查找到,原因就是因为数据库文件没有被更新。为了避免这种情况,可以在使用locate之前,先使用updatedb命令,手动更新数据库。
格式:locate [OPTION]… [PATTERN]…

locate命令格式

 - locate文件名
在后台数据库中按文件名搜索,搜索速度更快

 - /var/lib/mlocate/mlocate.db
locate命令所搜索的后台数据库

 - update
 更新数据库

/etc/updatedb.conf配置文件
PRUNE_BIND_MOUNTS = "yes"	//开启搜索限制
      2 PRUNEFS = "9p afs anon_inodefs auto autofs bdev binfmt_misc cgroup cifs coda configfs c        puset debugfs devpts ecryptfs exofs fuse fusectl gfs gfs2 hugetlbfs inotifyfs iso9660 j        ffs2 lustre mqueue ncpfs nfs nfs4 nfsd pipefs proc ramfs rootfs rpc_pipefs securityfs s        elinuxfs sfs sockfs sysfs tmpfs ubifs udf usbfs" 		//搜索时,不搜索的文件系统
      3 PRUNENAMES = ".git .hg .svn"		//搜索时,不搜索的文件类型
      4 PRUNEPATHS = "/afs /media /net /sfs /tmp /udev /var/cache/ccache /var/spool/cups /var/s        pool/squid /var/tmp" 		//搜索时,不搜索的路径

选项

-b, --basename match only the base name of path names
-c, --count 只输出找到的数量
-d, --database DBPATH 使用DBPATH指定的数据库,而不是默认数据库 /var/lib/mlocate/mlocate.db
-e, --existing only print entries for currently existing files
-L, --follow follow trailing symbolic links when checking file existence (default)
-h, --help 显示帮助
-i, --ignore-case 忽略大小写
-l, --limit, -n LIMIT limit output (or counting) to LIMIT entries
-m, --mmap ignored, for backward compatibility
-P, --nofollow, -H don't follow trailing symbolic links when checking file existence
-0, --null separate entries with NUL on output
-S, --statistics don't search for entries, print statistics about eachused database
-q, --quiet 安静模式,不会显示任何错误讯息
-r, --regexp REGEXP 使用基本正则表达式
--regex 使用扩展正则表达式
-s, --stdio ignored, for backward compatibility
-V, --version 显示版本信息
-w, --wholename match whole path name (default)

查找某个文件的路径:
在这里插入图片描述
在etc目录下查找以my开头的文件:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/yuming226/article/details/82810497
今日推荐