Linux系统之whereis命令的基本使用

简介: Linux系统之whereis命令的基本使用

在这里插入图片描述

一、whereis命令介绍

whereis 命令在 Linux 系统中用于查找二进制文件、源代码文件和帮助手册页的位置。它主要搜索标准的可执行文件路径、特定配置文件路径以及手册页路径,对于定位系统命令或工具非常有用。

二、whereis命令的使用帮助

2.1 whereis命令的帮助信息

在命令行终端中,我们使用-h选项查询whereis命令的基本帮助信息。

[root@openEuler ~]# whereis  -h

Usage:
 whereis [options] [-BMS <dir>... -f] <name>

Locate the binary, source, and manual-page files for a command.

Options:
 -b         search only for binaries
 -B <dirs>  define binaries lookup path
 -m         search only for manuals and infos
 -M <dirs>  define man and info lookup path
 -s         search only for sources
 -S <dirs>  define sources lookup path
 -f         terminate <dirs> argument list
 -u         search for unusual entries
 -g         interpret name as glob (pathnames pattern)
 -l         output effective lookup paths

 -h, --help     display this help
 -V, --version  display version

For more details see whereis(1).

2.2 whereis命令帮助解释

用法:

whereis [选项] [-BMS <目录>... -f] <名称>

命令功能:

  • 查找命令的二进制文件、源文件和手册页文件的位置。

选项说明:

  • -b:仅查找二进制文件。
  • -B <目录>:指定查找二进制文件的路径。
  • -m:仅查找手册页和信息文件。
  • -M <目录>:指定查找手册页和信息文件的路径。
  • -s:仅查找源代码文件。
  • -S <目录>:指定查找源代码文件的路径。
  • -f:表示目录参数列表的结束。
  • -u:查找不符合常规的条目,即那些没有对应的二进制文件、手册页或源文件的项目。
  • -g:将名称解释为路径名模式(globbing pattern)。
  • -l:输出实际使用的查找路径。

帮助和版本信息:

  • -h, --help:显示帮助信息。
  • -V, --version:显示版本信息。

三、whereis命令的基本使用

3.1 查找命令的位置

查找 httpd的位置,包括其二进制文件、源码文件和手册页。

[root@openEuler ~]# whereis httpd
httpd: /usr/sbin/httpd /usr/lib64/httpd /etc/httpd /usr/share/httpd /usr/share/man/man8/httpd.8.gz

3.2 仅查找二进制文件

可以使用 -b 选项,仅查找二进制文件。

[root@openEuler ~]# whereis -b httpd
httpd: /usr/sbin/httpd /usr/lib64/httpd /etc/httpd /usr/share/httpd

3.3 仅查找手册页

可以使用 -m 选项,查看httpd的手册页。

[root@openEuler ~]# whereis -m httpd
httpd: /usr/share/man/man8/httpd.8.gz

3.4 输出实际使用的查找路径

使用-l选项,输出实际使用的查找路径,如下所示:

[root@openEuler ~]# whereis -l
bin: /usr/bin
bin: /usr/sbin
bin: /usr/lib
bin: /usr/lib64
bin: /etc
bin: /usr/games
bin: /usr/local/bin
bin: /usr/local/sbin
bin: /usr/local/etc
bin: /usr/local/lib
bin: /usr/local/games
bin: /usr/include
bin: /usr/local
bin: /usr/libexec
bin: /usr/share
bin: /opt/containerd/bin
man: /usr/share/man/es
man: /usr/share/man/man0p
man: /usr/share/man/zh_CN
man: /usr/share/man/da
man: /usr/share/man/man9
man: /usr/share/man/man4x
man: /usr/share/man/man3
man: /usr/share/man/man5x
man: /usr/share/man/man6x
man: /usr/share/man/pt
man: /usr/share/man/man6
man: /usr/share/man/mann
man: /usr/share/man/tr.UTF-8
man: /usr/share/man/man7x
man: /usr/share/man/it
man: /usr/share/man/man7
man: /usr/share/man/cs
man: /usr/share/man/man8
man: /usr/share/man/man1x
man: /usr/share/man/nl
man: /usr/share/man/tr
man: /usr/share/man/uk
man: /usr/share/man/man8x
man: /usr/share/man/ru
man: /usr/share/man/sv
man: /usr/share/man/pl
man: /usr/share/man/man3p
man: /usr/share/man/man2
man: /usr/share/man/man4
man: /usr/share/man/tr.ISO8859-9
man: /usr/share/man/id
man: /usr/share/man/man1p
man: /usr/share/man/sr
man: /usr/share/man/ja
man: /usr/share/man/man2x
man: /usr/share/man/man5
man: /usr/share/man/ro
man: /usr/share/man/man9x
man: /usr/share/man/de
man: /usr/share/man/sk
man: /usr/share/man/ko
man: /usr/share/man/man3x
man: /usr/share/man/pt_BR
man: /usr/share/man/fr
man: /usr/share/man/ca
man: /usr/share/man/man1
man: /usr/share/info
src: /usr/src/debug
src: /usr/src/kernels

3.5 指定自定义搜索路径

如果有特定的路径想要搜索,可以使用 -B, -M, 或 -S 来定义这些路径。例如,要在一个非标准目录/root/node-v14.17.0-linux-x64/bin 中查找node 的二进制文件:

[root@openEuler ~]# whereis -B /root/node-v14.17.0-linux-x64/bin  -b node
node: /root/node-v14.17.0-linux-x64/bin/node

四、注意事项

  1. 使用 -b, -m, 或 -s 选项可分别限制搜索仅限于二进制文件、手册页或源代码文件。
  2. 如果要查找非标准位置的文件,请结合 -B, -M, 或 -S 选项自定义搜索路径。
  3. 当命令未找到预期的结果时,可能是因为程序不是从标准路径安装的,考虑使用 findlocate 命令代替。
  4. 使用 -u 选项可以帮助发现那些缺少了通常应关联的文件(如手册页或二进制)的不寻常条目。
  5. 对于有多个版本或同名但不同用途的命令,whereis 可能会列出所有匹配项,注意甄别所需的具体路径。
  6. 记住 whereis 不会搜索 $PATH 环境变量中定义的所有路径,它有一套自己的默认搜索路径。
相关文章
|
2月前
|
存储 缓存 监控
Linux缓存管理:如何安全地清理系统缓存
在Linux系统中,内存管理至关重要。本文详细介绍了如何安全地清理系统缓存,特别是通过使用`/proc/sys/vm/drop_caches`接口。内容包括清理缓存的原因、步骤、注意事项和最佳实践,帮助你在必要时优化系统性能。
221 78
|
14天前
|
网络协议 Unix Linux
深入解析:Linux网络配置工具ifconfig与ip命令的全面对比
虽然 `ifconfig`作为一个经典的网络配置工具,简单易用,但其功能已经不能满足现代网络配置的需求。相比之下,`ip`命令不仅功能全面,而且提供了一致且简洁的语法,适用于各种网络配置场景。因此,在实际使用中,推荐逐步过渡到 `ip`命令,以更好地适应现代网络管理需求。
28 11
|
26天前
|
缓存 安全 Linux
Linux系统查看操作系统版本信息、CPU信息、模块信息
在Linux系统中,常用命令可帮助用户查看操作系统版本、CPU信息和模块信息
93 23
|
2月前
|
Linux Shell 网络安全
Kali Linux系统Metasploit框架利用 HTA 文件进行渗透测试实验
本指南介绍如何利用 HTA 文件和 Metasploit 框架进行渗透测试。通过创建反向 shell、生成 HTA 文件、设置 HTTP 服务器和发送文件,最终实现对目标系统的控制。适用于教育目的,需合法授权。
85 9
Kali Linux系统Metasploit框架利用 HTA 文件进行渗透测试实验
|
2月前
|
Linux Shell
Linux 10 个“who”命令示例
Linux 10 个“who”命令示例
95 14
Linux 10 个“who”命令示例
|
2月前
|
Ubuntu Linux
Linux 各发行版安装 ping 命令指南
如何在不同 Linux 发行版(Ubuntu/Debian、CentOS/RHEL/Fedora、Arch Linux、openSUSE、Alpine Linux)上安装 `ping` 命令,详细列出各发行版的安装步骤和验证方法,帮助系统管理员和网络工程师快速排查网络问题。
185 20
|
2月前
|
Linux
linux查看目录下的文件夹命令,find查找某个目录,但是不包括这个目录本身?
通过本文的介绍,您应该对如何在 Linux 系统中查看目录下的文件夹以及使用 `find` 命令查找特定目录内容并排除该目录本身有了清晰的理解。掌握这些命令和技巧,可以大大提高日常文件管理和查找操作的效率。 在实际应用中,灵活使用这些命令和参数,可以帮助您快速定位和管理文件和目录,满足各种复杂的文件系统操作需求。
122 8
|
2月前
|
存储 监控 Linux
嵌入式Linux系统编程 — 5.3 times、clock函数获取进程时间
在嵌入式Linux系统编程中,`times`和 `clock`函数是获取进程时间的两个重要工具。`times`函数提供了更详细的进程和子进程时间信息,而 `clock`函数则提供了更简单的处理器时间获取方法。根据具体需求选择合适的函数,可以更有效地进行性能分析和资源管理。通过本文的介绍,希望能帮助您更好地理解和使用这两个函数,提高嵌入式系统编程的效率和效果。
118 13
|
2月前
|
网络协议 Linux 应用服务中间件
kali的常用命令汇总Linux
kali的常用命令汇总linux
119 7
|
3月前
|
Linux 数据库
Linux中第一次使用locate命令报错?????
在Linux CentOS7系统中,使用`locate`命令时出现“command not found”错误,原因是缺少`mlocate`包。解决方法是通过`yum install mlocate -y`或`apt-get install mlocate`安装该包,并执行`updatedb`更新数据库以解决后续的“can not stat”错误。
61 9