#Bash 的 whereis 命令
whereis [OPTION]... NAME...
功能
定位二进制文件、源码文件和手册文件的路径。
类型
可执行文件(/usr/bin/whereis),属于 util-linux。
参数
OPTION选项:-b- 查找二进制文件-m- 查找手册文件-s- 查找源码文件-u- 仅显示居然异常条目的命令名称-B list- 指定搜索二进制文件的目录列表;以空格分隔条目-M list- 指定搜索手册文件的目录列表;以空格分隔条目-S list- 指定搜索源码文件的目录列表;以空格分隔条目-f- 终止目录列表;在-B-M-S选项后必须使用此选项结束-l- 显示此命令的搜索目录列表-g- 将接下来的名称解释为 glob(7) 模式-h,--help- 显示帮助-V,--version- 显示版本
NAME- 要定位的文件列表
#示例
定位文件
$ whereis whereis
whereis: /usr/bin/whereis /usr/share/man/man1/whereis.1.gz
查看搜索路径
$ whereis -l # 查看 whereis 的默认搜索路径
bin: /usr/bin
bin: /usr/sbin
bin: /usr/lib/x86_64-linux-gnu
bin: /usr/lib
bin: /usr/lib32
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/qt-6.7.1/bin
bin: /opt/qt-wasm-6.7.1/bin
bin: /home/planc/.cargo/bin
man: /usr/share/man/zh_CN
man: /usr/share/man/man1
man: /usr/share/man/hu
man: /usr/share/man/zh_TW
man: /usr/share/man/id
man: /usr/share/man/man3
man: /usr/share/man/da
man: /usr/share/man/vi
man: /usr/share/man/sr
man: /usr/share/man/man8
man: /usr/share/man/man4
man: /usr/share/man/ru
man: /usr/share/man/man6
man: /usr/share/man/sv
man: /usr/share/man/man5
man: /usr/share/man/man2
man: /usr/share/man/pt
man: /usr/share/man/man9
man: /usr/share/man/sl
man: /usr/share/man/pt_BR
man: /usr/share/man/cs
man: /usr/share/man/ko
man: /usr/share/man/uk
man: /usr/share/man/tr
man: /usr/share/man/ja
man: /usr/share/man/fr
man: /usr/share/man/es
man: /usr/share/man/man7
man: /usr/share/man/nl
man: /usr/share/man/de
man: /usr/share/man/pl
man: /usr/share/man/fi
man: /usr/share/man/ro
man: /usr/share/man/hr
man: /usr/share/man/it
man: /usr/share/info
src: /usr/src/linux-headers-6.8.0-101-generic
src: /usr/src/linux-headers-6.8.0-87-generic
src: /usr/src/linux-headers-6.8.0-87
src: /usr/src/linux-headers-6.8.0-101
src: /usr/src/python3.12
#相关命令
| 命令 | 说明 |
|---|---|
| which | 定位 PATH 环境变量中命令的路径 |
#推荐阅读
#手册
WHEREIS(1) User Commands WHEREIS(1)
NAME
whereis - locate the binary, source, and manual page files for a
command
SYNOPSIS
whereis [options] [-BMS directory... -f] name...
DESCRIPTION
whereis locates the binary, source and manual files for the specified
command names. The supplied names are first stripped of leading
pathname components. Prefixes of s. resulting from use of source code
control are also dealt with. whereis then attempts to locate the
desired program in the standard Linux places, and in the places
specified by $PATH and $MANPATH.
The search restrictions (options -b, -m and -s) are cumulative and
apply to the subsequent name patterns on the command line. Any new
search restriction resets the search mask. For example,
whereis -bm ls tr -m gcc
searches for "ls" and "tr" binaries and man pages, and for "gcc" man
pages only.
The options -B, -M and -S reset search paths for the subsequent name
patterns. For example,
whereis -m ls -M /usr/share/man/man1 -f cal
searches for "ls" man pages in all default paths, but for "cal" in the
/usr/share/man/man1 directory only.
OPTIONS
-b
Search for binaries.
-m
Search for manuals.
-s
Search for sources.
-u
Only show the command names that have unusual entries. A command is
said to be unusual if it does not have just one entry of each
explicitly requested type. Thus 'whereis -m -u *' asks for those
files in the current directory which have no documentation file, or
more than one.
-B list
Limit the places where whereis searches for binaries, by a
whitespace-separated list of directories.
-M list
Limit the places where whereis searches for manuals and
documentation in Info format, by a whitespace-separated list of
directories.
-S list
Limit the places where whereis searches for sources, by a
whitespace-separated list of directories.
-f
Terminates the directory list and signals the start of filenames.
It must be used when any of the -B, -M, or -S options is used.
-l
Output the list of effective lookup paths that whereis is using.
When none of -B, -M, or -S is specified, the option will output the
hard-coded paths that the command was able to find on the system.
-g
Interpret the next names as a glob(7) patterns. whereis always
compares only filenames (aka basename) and never complete path.
Using directory names in the pattern has no effect. Don’t forget
that the shell interprets the pattern when specified on the command
line without quotes. It’s necessary to use quotes for the name, for
example:
whereis -g 'find*'
-h, --help
Display help text and exit.
-V, --version
Print version and exit.
FILE SEARCH PATHS
By default whereis tries to find files from hard-coded paths, which are
defined with glob patterns. The command attempts to use the contents of
$PATH and $MANPATH environment variables as default search path. The
easiest way to know what paths are in use is to add the -l listing
option. Effects of the -B, -M, and -S are displayed with -l.
ENVIRONMENT
WHEREIS_DEBUG=all
enables debug output.
EXAMPLES
To find all files in /usr/bin which are not documented in /usr/man/man1
or have no source in /usr/src:
cd /usr/bin
whereis -u -ms -M /usr/man/man1 -S /usr/src -f *
REPORTING BUGS
For bug reports, use the issue tracker at
https://github.com/util-linux/util-linux/issues.
AVAILABILITY
The whereis command is part of the util-linux package which can be
downloaded from Linux Kernel Archive
<https://www.kernel.org/pub/linux/utils/util-linux/>.
util-linux 2.39.3 2023-11-21 WHEREIS(1)