10

Linux whereis命令查找二进制文件

 1 year ago
source link: https://www.myfreax.com/whereis-command-in-linux/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Linux whereis命令查找二进制文件

whereis是一个命令行程序,可让您查找给定命令的二进制文件

Updated At 7 Nov 2022 2 min read
By myfreax
Linux whereis命令查找二进制文件

Linux whereis命令查找二进制文件

whereis是一个命令行程序,可让您查找给定命令的二进制文件,源文件和手册页文件的位置。

在本教程中,我们将向您展示如何在Linux使用whereis命令。包括whereis语法与选项,一次搜索多个二进制文件,指定目录查找文件等。

whereis命令的语法形式是whereis [OPTIONS] FILE_NAME...

不带任何选项运行whereis命令时,它将会在环境变量PATH包含的目录,源文件和手册文件目录中搜索指定的命令。

你可以使用-l选项运行命令whereis -l列出whereis命令要搜索的目录。例如,要获取bash命令的信息,请运行命令whereis bash

whereis -l
whereis bash
bash: /bin/bash /etc/bash.bashrc /usr/share/man/man1/bash.1.gz

在输出中,bash是要获取信息的命令,/bin/bash是bash二进制文件的路径,/etc/bash.bashrc是源文件,/usr/share/man/man1/bash.1.gz是手册页。

如果您要搜索的命令不存在,whereis将打印命令名称。您还可以使用whereis 一次搜索多个命令。

例如命令whereis netcat uptime的输出将包含netcatuptime命令的信息。

whereis netcat uptime
netcat: /bin/netcat /usr/share/man/man1/netcat.1.gz
uptime: /usr/bin/uptime /usr/share/man/man1/uptime.1.gz

要仅搜索命令二进制文件的位置,请使用-p选项运行whereis。例如要查找ping命令的二进制文件位置,可以运行命令whereis -p ping

当仅搜索命令二进制文件的位置时,请优先使用which或​type命令。要仅搜索源文件,请使用-s选项。

如果源文件存在,则whereis将打印其位置。-m选项仅允许您搜索手册文件的位置。

whereis -p ping
whereis -s command
whereis -m command
ping: /bin/ping

要限制whereis搜索二进制文件的位置,请使用-B选项,对于手册文件的位置,请选择-M选项,对于源请使用-S。每个选项均以空格分隔。

例如,要在/bin目录中搜索cp命令的二进制文件,请运行命令whereis -b -B /bin -f cp

whereis -b -B /bin -f cp
cp: /bin/cp

whereis命令用于查找给定命令的二进制文件,源文件和手册文件。如果您有任何疑问或反馈,请在下面发表评论。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK