Linux命令:whereis

摘要:转自恋猫大鲤鱼
https://dablelv.blog.csdn.net/article/details/102980621

1. 命令简解

  whereis 命令用于查找命令二进制程序、源代码文件和 man  手册等相关文件路径,如果仅显示命令的绝对路径,可以用 which 命令, 其他普通文件的查找需要使用 locate 和 find 命令。

  whereis 默认的搜索路径是从硬编码路径中查找文件,硬编码路径是用 glob patterns 定义的, 以及环境变量 PATH 和MANPATH定义的路径。要知道使用了哪些路径,最简单的方法是使用 -l 选项来查看。

2. 命令格式

whereis [OPTIONS] [-BMS DIRECTORY...-f] NAME ...

 

3.选项说明

-b
    只搜索二进制文件        
-m
    只搜索 man 手册
-s
    只搜索源代码
-u
    只展示有关特殊文件(二进制程序、源代码文件、man 手册)的命令名称
-B LIST
    指定二进制文件查找目录,使用空格分隔
-S LIST
    指定源代码文件查找目录,使用空格分隔
-f
    在使用 -S -M -B 选项时,必须使用这个选项,用于表示目录的结束,命令名的开始
-l
    输出正在使用的有效查找路径

 

4. 常用示例

  1. 查看命令 which 的二进制文件与帮助手册的路径

pi@raspberrypi:~ $ whereis which
which: /usr/bin/which /bin/which /usr/share/man/man1/which.1.gz

  2. 只搜索二进制文件 which 的路径

pi@raspberrypi:~ $ whereis -b which
which: /usr/bin/which /bin/which

 

  3. 只搜索命令 which 帮助手册的路径

pi@raspberrypi:~ $ whereis -m which
which: /usr/share/man/man1/which.1.gz

  4. 指定查找命令 passwd 的目录为 /usr/bin

pi@raspberrypi:~ $ whereis -b -B /usr/bin -f passwd
passwd: /usr/bin/passwd

  5. 查看 whereis 默认的搜索路径

pi@raspberrypi:~ $ whereis -l
bin: /usr/bin
bin: /usr/sbin
bin: /lib/arm-linux-gnueabihf
bin: /usr/lib/arm-linux-gnueabihf
...

 

posted @ 2021-01-04 09:57  雨竹枫  阅读(407)  评论(0编辑  收藏  举报