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 环境变量中定义的所有路径,它有一套自己的默认搜索路径。
相关文章
|
8月前
|
Linux 应用服务中间件 Shell
二、Linux文本处理与文件操作核心命令
熟悉了Linux的基本“行走”后,就该拿起真正的“工具”干活了。用grep这个“放大镜”在文件里搜索内容,用find这个“探测器”在系统中寻找文件,再用tar把东西打包带走。最关键的是要学会使用管道符|,它像一条流水线,能把这些命令串联起来,让简单工具组合出强大的功能,比如 ps -ef | grep 'nginx' 就能快速找出nginx进程。
933 1
二、Linux文本处理与文件操作核心命令
|
8月前
|
Ubuntu Linux Anolis
Linux系统禁用swap
本文介绍了在新版本Linux系统(如Ubuntu 20.04+、CentOS Stream、openEuler等)中禁用swap的两种方法。传统通过注释/etc/fstab中swap行的方式已失效,现需使用systemd管理swap.target服务或在/etc/fstab中添加noauto参数实现禁用。方法1通过屏蔽swap.target适用于新版系统,方法2通过修改fstab挂载选项更通用,兼容所有系统。
733 3
Linux系统禁用swap
|
8月前
|
Linux
Linux系统修改网卡名为eth0、eth1
在Linux系统中,可通过修改GRUB配置和创建Udev规则或使用systemd链接文件,将网卡名改为`eth0`、`eth1`等传统命名方式,适用于多种发行版并支持多网卡配置。
1301 3
|
8月前
|
Linux
linux命令—stat
`stat` 是 Linux 系统中用于查看文件或文件系统详细状态信息的命令。相比 `ls -l`,它提供更全面的信息,包括文件大小、权限、所有者、时间戳(最后访问、修改、状态变更时间)、inode 号、设备信息等。其常用选项包括 `-f` 查看文件系统状态、`-t` 以简洁格式输出、`-L` 跟踪符号链接,以及 `-c` 或 `--format` 自定义输出格式。通过这些选项,用户可以灵活获取所需信息,适用于系统调试、权限检查、磁盘管理等场景。
540 137
|
9月前
|
Ubuntu Linux
计算机基础知识:linux系统怎么安装?
在虚拟机软件中创建一个新的虚拟机,并选择相应操作系统类型和硬盘空间大小等参数。将下载的 ISO 镜像文件加载到虚拟机中。启动虚拟机,进入安装界面,并按照步骤进行安装。安装完成后,可以在虚拟机中使用 Linux 系统。
|
8月前
|
安全 Ubuntu Unix
一、初识 Linux 与基本命令
玩转Linux命令行,就像探索一座新城市。首先要熟悉它的“地图”,也就是/根目录下/etc(放配置)、/home(住家)这些核心区域。然后掌握几个“生存口令”:用ls看周围,cd去别处,mkdir建新房,cp/mv搬东西,再用cat或tail看文件内容。最后,别忘了随时按Tab键,它能帮你自动补全命令和路径,是提高效率的第一神器。
1429 58
|
Ubuntu Linux 网络安全
Linux系统初始化脚本
一款支持Rocky、CentOS、Ubuntu、Debian、openEuler等主流Linux发行版的系统初始化Shell脚本,涵盖网络配置、主机名设置、镜像源更换、安全加固等多项功能,适配单/双网卡环境,支持UEFI引导,提供多版本下载与持续更新。
797 3
Linux系统初始化脚本
|
7月前
|
存储 安全 Linux
Linux卡在emergency mode怎么办?xfs_repair 命令轻松解决
Linux虚拟机遇紧急模式?别慌!多因磁盘挂载失败。本文教你通过日志定位问题,用`xfs_repair`等工具修复文件系统,三步快速恢复。掌握查日志、修磁盘、验重启,轻松应对紧急模式,保障系统稳定运行。
1295 2
|
8月前
|
Unix Linux 程序员
Linux文本搜索工具grep命令使用指南
以上就是对Linux环境下强大工具 `grep` 的基础到进阶功能介绍。它不仅能够执行简单文字查询任务还能够处理复杂文字处理任务,并且支持强大而灵活地正则表达规范来增加查询精度与效率。无论您是程序员、数据分析师还是系统管理员,在日常工作中熟练运用该命令都将极大提升您处理和分析数据效率。
682 16
|
8月前
|
缓存 监控 Linux
Linux内存问题排查命令详解
Linux服务器卡顿?可能是内存问题。掌握free、vmstat、sar三大命令,快速排查内存使用情况。free查看实时内存,vmstat诊断系统整体性能瓶颈,sar实现长期监控,三者结合,高效定位并解决内存问题。
800 0
Linux内存问题排查命令详解