Linux 搜索命令 whereis which locate

目录

搜索命令

whereis 命令

which 命令

locate 命令


搜索命令

whereis 命令

  • whereis 是搜索系统命令的命令,也就是说,whereis 命令不能搜索普通文件,而只能搜索系统命令。
  • whereis 命令的基本信息如下。
    • 命令名称:whereis。
    • 英文原意:locate the binary, source, and manual page files for a command。
    • 所在路径:/usr/bin/whereis。
    • 执行权限:所有用户。
    • 功能描述:查找二进制命令、源文件和帮助文档的命令。

which 命令

  • which 也是搜索系统命令的命令。和 whereis 命令的区别在于:
    • whereis 命令可以在查找到二进制命令的同时,查找到帮助文档的位置
    • which 命令在查找到二进制命令的同时,如果这个命令有别名,则还可以找到别名命令
  • which 命令的基本信息如下。
    • 命令名称:which。
    • 英文原意:shows the full path of (shell) commands。
    • 所在路径:/usr/bin/which。
    • 执行权限:所有用户。
    • 功能描述:列出命令的所在路径。

locate 命令

  • 基本用法
    • locate 命令才是可以按照文件名搜索普通文件的命令。
    • 优点:按照数据库搜索,搜索速度快,消耗资源小。数据库位置/var/lib/mlocate/mlocate.db,可以使用 updatedb 命令强制更新数据库。
    • 缺点:只能按照文件名来搜索文件,而不能执行更复杂的搜索,比如按照权限、大小、修改时间等搜索文件。
  • locate 命令的基本信息如下
    • 命令名称:locate。
    • 英文原意:find files by name。
    • 所在路径:/usr/bin/locate。
    • 执行权限:所有用户。
    • 功能描述:按照文件名搜索文件。
  • 配置文件
[root@localhost ~]# vi /etc/updatedb.conf
PRUNE_BIND_MOUNTS = "yes"
#开启搜索限制,也就是让这个配置文件生效
PRUNEFS = "……"
#在 locate 执行搜索时,禁止搜索这些文件系统类型
PRUNENAMES = "……"
#在 locate 执行搜索时,禁止搜索带有这些扩展名的文件
PRUNEPATHS = "……"
#在 locate 执行搜索时,禁止搜索这些系统目录

【注】:参考尚硅谷沈超老师教程

猜你喜欢

转载自blog.csdn.net/baidu_41388533/article/details/107607631
今日推荐