
一,什么是whereis命令
https://man.he.net/man1/whereiswhereis - 查找命令的二进制文件、源代码文件和手册页文件
whereis 用于查找指定命令名的二进制文件、源代码文件和手册文件。首先会去除所提供名称中的前导路径组件。对于使用源代码控制时产生的“s.”前缀,也会进行处理。然后,whereis 会尝试在标准的 Linux 位置以及 $PATH 和 $MANPATH 指定的位置查找所需的程序。
搜索限制选项(-b、-m 和 -s)是累积生效的,并作用于命令行中后续的名称模式,任何新的搜索限制选项都会重置当前的搜索掩码。例如:
whereis -bm ls tr -m gcc表示:查找 "ls" 和 "tr" 的二进制文件和手册页,而仅查找 "gcc" 的手册页。
选项 -B、-M 和 -S 用于为后续的名称模式重设搜索路径。例如:
whereis -m ls -M /usr/share/man/man1 -f cal表示:在所有默认路径中查找 "ls" 的手册页,但仅在 /usr/share/man/man1 目录中查找 "cal" 的手册页。
文件搜索路径默认情况下,whereis 会从硬编码的路径中查找文件,这些路径是使用通配符(glob)模式定义的。该命令会尝试使用环境变量 $PATH 和 $MANPATH 的内容作为默认的搜索路径。要了解当前实际使用的路径,最简单的方法是加上 -l 列出选项。使用 -B、-M 和 -S 选项所指定的路径也会在使用 -l 时一并显示。
二,参数选项
[root@master1 ~]# whereis -h用法:whereis [选项] 文件选项:-b 只搜索二进制文件-B <目录> 定义二进制文件查找路径-m 只搜索 man 手册-M <目录> 定义 man 手册查找路径-s 只搜索源代码-S <目录> 定义源代码查找路径-f 终止 <目录> 参数列表-u 搜索不常见记录-l 输出有效查找路径更多信息请参阅 whereis(1)。
三,例子
whereis 不会列出所有相关文件(如配置文件),它只查预定义的路径。要找配置文件建议用 find 或 rpm -qc(RPM 系统)[root@master1 ~]# whereis nginxnginx: /usr/local/nginx
[root@master1 ~]# whereis -b pythonpython: /usr/bin/python /usr/bin/python2.7 /usr/bin/python2.7-config /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/include/python2.7
3、只查找手册页(man pages)
[root@master1 ~]# whereis -m lsls: /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz
4、只查找源代码(通常对系统命令无效,除非你安装了源码包)
[root@master1 ~]# whereis -s bashbash:[root@master1 ~]#
-M指定手册页搜索路径为 /usr/local/man-f表示后面的是要查找的文件名(必须加 -f来分隔路径和文件名)[root@master1 ~]# whereis -M /usr/local/man -f lsls: /usr/bin/ls
[root@master1 ~]# whereis -lbin: /usr/binbin: /usr/sbinbin: /usr/libbin: /usr/lib64bin: /etcbin: /usr/etcbin: /usr/gamesbin: /usr/local/binbin: /usr/local/sbinbin: /opt/jdk1.8.0_351_arm/binbin: /opt/hbase-1.2.0/binbin: /usr/java/jdk1.8.0_131/binbin: /usr/java/jdk1.8.0_131/jre/binman: /usr/share/man/man0pman: /usr/share/man/man1man: /usr/share/man/ukman: /usr/share/man/caman: /usr/share/man/overridesman: /usr/share/man/ensrc: /usr/src/debugsrc: /usr/src/kernels
[root@master1 ~]# whereis -u *log: /usr/share/man/man3/log.3.gz /usr/share/man/man3p/log.3p.gzlog: /usr/share/man/man3/log.3.gz /usr/share/man/man3p/log.3p.gzraw: /usr/bin/raw /usr/share/man/man3/raw.3x.gz /usr/share/man/man7/raw.7.gz /usr/share/man/man8/raw.8.gztelnet: /usr/bin/telnet /usr/share/man/man1/telnet.1.gztest: /usr/bin/test /opt/hbase-1.2.0/bin/test /usr/share/man/man1/test.1.gz /usr/share/man/man1p/test.1p.gztime: /usr/bin/time /usr/include/time.h /usr/share/man/man1/time.1.gz /usr/share/man/man1p/time.1p.gz /usr/share/man/man2/time.2.gz /usr/share/man/man3p/time.3p.gz /usr/share/man/man7/time.7.gz /usr/share/man/mann/time.n.gz
[root@master1 ~]# whereis -bm gcc make curlgcc: /usr/bin/gcc /usr/lib/gcc /usr/libexec/gcc /usr/share/man/man1/gcc.1.gzmake: /usr/bin/make /usr/share/man/man1/make.1.gz /usr/share/man/man1p/make.1p.gzcurl: /usr/bin/curl /usr/share/man/man1/curl.1.gz
四,补充
环境变量,启用调试输出。
WHEREIS_DEBUG=all报告缺陷
如需提交 bug 报告,请使用以下 issue 跟踪地址:https://github.com/karelzak/util-linux/issues
可用性
whereis命令属于util-linux 软件包的一部分,可从Linux内核归档网站下载:https://www.kernel.org/pub/linux/utils/util-linux/
五,总结
whereis 是找命令安装路径的命令,非常有用,之前也写过一篇相关命令的文档,有兴趣也可以阅读下《linux下几个文件查找和比较浅介》
最后的最后(Last but not least),欢迎交流:
关注公众号留言,或者在下方直接留言: