mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
[手动选题][tech]: 20230103.3 ⭐️ Whereis Command in Linux and BSD with Examples.md
This commit is contained in:
parent
5dba280521
commit
a5180f78e3
@ -0,0 +1,152 @@
|
||||
[#]: 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: " "
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
Whereis Command in Linux and BSD with Examples
|
||||
======
|
||||
|
||||
**Here’s a beginner’s 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, let’s look at the syntax.
|
||||
|
||||
### Syntax
|
||||
|
||||
Here’s 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.
|
||||
|
||||
Let’s 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 doesn’t find anything, it only shows the argument’s 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
|
||||
```
|
||||
|
||||
Here’s 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
|
Loading…
Reference in New Issue
Block a user