translated

This commit is contained in:
geekpi 2023-01-12 08:53:15 +08:00
parent 2a752454de
commit 19fa79d2e9
2 changed files with 149 additions and 152 deletions

View File

@ -1,152 +0,0 @@
[#]: subject: "Whereis Command in Linux and BSD with Examples"
[#]: via: "https://www.debugpoint.com/whereis-command-linux/"
[#]: author: "Arindam https://www.debugpoint.com/author/admin1/"
[#]: collector: "lkxed"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Whereis Command in Linux and BSD with Examples
======
**Heres a beginners guide on understanding whereis command in Linux & BSD with several examples.**
![][1]
_This article is part of the [Linux command][2] learning series._
### whereis command
The `whereis` command is a command line program that helps you to find out the path or location of any binary executable, source file or manual page.
Before we show you how to use `whereis` command, lets look at the syntax.
### Syntax
Heres the syntax for whereis command:
```
whereis [OPTIONS] FILE_NAME
```
The argument of whereis command is the program name or file name you want to search. The argument is mandatory.
By default, it searches for the program in the path defined in environment variables such as HOME, USER, SHELL, etc.
Lets take a look at some examples.
### Examples of whereis command in Linux and BSD
A simple example of whereis command is below where I am trying to search firefox. In the output below, you can see the list of paths containing firefox files or executables displayed.
```
$ whereis firefox
firefox: /usr/bin/firefox /usr/lib64/firefox /etc/firefox /usr/share/man/man1/firefox.1.gz
```
![Simple example of whereis command in Linux][3]
The command with option -l displays the list of paths where it searches. For example:
```
$ 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
```
If the whereis command doesnt find anything, it only shows the arguments name. For example, if I search nano in Linux where is it not installed, it outputs the following:
```
$ whereis nano
```
```
nano:
```
You can always add multiple arguments if you want to search for more. For example below command searches for both bash and nano, and this is the output:
```
$ whereis bash nano
bash: /usr/bin/bash /usr/share/man/man1/bash.1.gz /usr/share/info/bash.info.gz
nano: /usr/bin/nano /usr/share/nano /usr/share/man/man1/nano.1.gz /usr/share/info/nano.info.gz
```
You can also search for specific file types, such as binaries, using -b option. The following command only tells you the binary paths of nano.
```
$ whereis -b nano
nano: /usr/bin/nano /usr/share/nano
```
Similarly, the -s option searches for source files, and the -m option searches for manual pages.
```
$ whereis -m nano
nano: /usr/share/man/man1/nano.1.gz /usr/share/info/nano.info.gz
```
You can also combine the above options for a more extensive search. For example, the following command searches for nano and firefox binary, manual pages and for bash, only manual pages.
```
$ whereis -bm nano firefox -m bash
nano: /usr/bin/nano /usr/share/nano /usr/share/man/man1/nano.1.gz /usr/share/info/nano.info.gz
firefox-m:
bash: /usr/bin/bash /usr/share/man/man1/bash.1.gz /usr/share/info/bash.info.gz
```
Heres a summary of the options:
| Option | Description |
| :- | :- |
| **-b** | Search only for binaries. |
| **-m** | Search only for manual sections. |
| **-s** | Search only for sources. |
| **-u** | Search for unusual entries. A file is said to be unusual if it does not have one entry of each requested type. Thus whereis -m -u * asks for those files in the current directory which have no documentation. |
| **-B** | Change or otherwise limit the places where whereis searches for binaries. |
| **-M** | Change or otherwise limit the places where whereis searches for manual sections. |
| **-S** | Change or otherwise limit the places where whereis searches for sources. |
| **-f** | Terminate the last directory list and signals the start of file names, and must be used when any of the -B, -M, or -S options are used. |
### Closing Notes
I hope this article helps you to understand whereis command and its basics. You can also read the[whereis man pages][4] to learn more. Let me know if you have any questions.
**This article is part of the [Linux command][2] learning series**.
[_Using Mastodon? Follow us at floss.social/@debugpoint_][5]
--------------------------------------------------------------------------------
via: https://www.debugpoint.com/whereis-command-linux/
作者:[Arindam][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.debugpoint.com/author/admin1/
[b]: https://github.com/lkxed
[1]: https://www.debugpoint.com/wp-content/uploads/2023/01/whereis-head.jpg
[2]: https://www.debugpoint.com/category/linux-commands
[3]: https://www.debugpoint.com/wp-content/uploads/2023/01/Simple-example-of-whereis-command-in-Linux.jpg
[4]: https://linux.die.net/man/1/whereis
[5]: https://floss.social/@debugpoint

View File

@ -0,0 +1,149 @@
[#]: subject: "Whereis Command in Linux and BSD with Examples"
[#]: via: "https://www.debugpoint.com/whereis-command-linux/"
[#]: author: "Arindam https://www.debugpoint.com/author/admin1/"
[#]: collector: "lkxed"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Linux 和 BSD 中的 Whereis 命令及示例
======
**这是一份关于如何理解 Linux 和 BSD 中 whereis 命令的初学者指南,其中有几个例子。**
![][1]
_这篇文章是 [Linux 命令][2]学习系列的一部分。_
### whereis 命令
`whereis` 命令是一个命令行程序,可以帮助你找出任何二进制可执行文件、源文件或手册页的路径或位置。
在告诉你如何使用 `whereis` 命令之前,让我们先看看其语法。
### 语法
以下是 whereis 命令的语法:
```
whereis [OPTIONS] FILE_NAME
```
whereis 命令的参数是你要搜索的程序名或文件名。该参数是强制性的。
默认情况下,它在环境变量(如 HOME、USER、SHELL 等)中定义的路径中搜索程序。
让我们看下一些例子。
### Linux 和 BSD 中 whereis 命令的例子
下面是 whereis 命令的一个简单例子,我试图搜索 firefox。在下面的输出中你可以看到包含 firefox 文件或可执行文件的路径列表。
```
$ whereis firefox
firefox: /usr/bin/firefox /usr/lib64/firefox /etc/firefox /usr/share/man/man1/firefox.1.gz
```
![Linux 中 whereis 命令的简单例子][3]
带有选项 -l 的命令会显示其搜索的路径列表。比如:
```
$ 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
```
如果 whereis 命令没有找到任何东西,它只显示参数的名称。例如,如果我在 Linux 中搜索 nano它没有安装它的输出如下
```
$ whereis nano
```
```
nano:
```
如果你想搜索更多的参数,你可以随时添加多个参数。例如,下面的命令同时搜索 bash 和 nano输出结果是这样的
```
$ whereis bash nano
bash: /usr/bin/bash /usr/share/man/man1/bash.1.gz /usr/share/info/bash.info.gz
nano: /usr/bin/nano /usr/share/nano /usr/share/man/man1/nano.1.gz /usr/share/info/nano.info.gz
```
你也可以使用 -b 选项搜索特定的文件类型,比如二进制文件。下面的命令只告诉你 nano 的二进制路径。
```
$ whereis -b nano
nano: /usr/bin/nano /usr/share/nano
```
同样,-s 选项可以搜索源文件,而 -m 选项可以搜索手册页。
```
$ whereis -m nano
nano: /usr/share/man/man1/nano.1.gz /usr/share/info/nano.info.gz
```
你也可以结合上面的选项来进行更广泛的搜索。例如,下面的命令可以搜索 nano 和 firefox 的二进制、手册页,而对于 bash只搜索手册页。
```
$ whereis -bm nano firefox -m bash
nano: /usr/bin/nano /usr/share/nano /usr/share/man/man1/nano.1.gz /usr/share/info/nano.info.gz
firefox-m:
bash: /usr/bin/bash /usr/share/man/man1/bash.1.gz /usr/share/info/bash.info.gz
```
下面是选项的摘要:
| 选项 | 描述 |
| :- | :- |
| **-b** | 只搜索二进制文件。|
| **-m** | 只搜索手册部分。|
| **-s** | 只搜索源码。|
| **-u** | 搜索不寻常的条目。如果一个文件没有所要求的每种类型的条目就被称为不寻常。因此“whereis -m -u *” 会查询当前目录中没有文档的那些文件。|
| **-B** | 改变或限制 whereis 搜索二进制文件的地方。|
| **-M** | 更改或限制 whereis 搜索手册的位置。|
| **-S** | 更改或以其他方式限制 whereis 搜索源码的位置。|
| **-f** | 终止最后一个目录列表并指示文件名的开始,并且必须在使用任何 -B、-M 或 -S 选项时使用。|
### 结束语
我希望这篇文章能够帮助你理解 whereis 命令及其基本原理。你也可以阅读 [whereis 手册页][4]来了解更多。如果你有任何问题,请告诉我。
**本文是 [Linux 命令][2]学习系列的一部分**。
--------------------------------------------------------------------------------
via: https://www.debugpoint.com/whereis-command-linux/
作者:[Arindam][a]
选题:[lkxed][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.debugpoint.com/author/admin1/
[b]: https://github.com/lkxed
[1]: https://www.debugpoint.com/wp-content/uploads/2023/01/whereis-head.jpg
[2]: https://www.debugpoint.com/category/linux-commands
[3]: https://www.debugpoint.com/wp-content/uploads/2023/01/Simple-example-of-whereis-command-in-Linux.jpg
[4]: https://linux.die.net/man/1/whereis