Whereis usage in linux, linuxwhereis

Source: Internet
Author: User

Whereis usage in linux, linuxwhereis

The whereis command can only be used for searching program names, and only binary files (parameter-B), man description files (parameter-m), and source code files (parameter-s) can be searched ). If the parameter is omitted, all information is returned.

Compared with find, whereis searches very quickly, because the linux system records all files in the system in a database file, when whereis and the locate described below are used, data will be searched from the database, instead of traversing the hard disk like the find command, which will naturally be very efficient.

However, this database file is not updated in real time. It is updated once a week by default. Therefore, when we use whereis and locate to find the file, we sometimes find the deleted data, you can't find the file you just created because the database file is not updated.

Command Format:

Whereis [-bmsu] [BMS directory name-f] File Name

Command function:

The whereis command locates executable files, source code files, and help files in the file system. The attributes of these files should belong to the original code, binary file, or help file.

The whereis Program also provides the ability to search for source code, specify a backup search path, and search for unusual items.

Command parameters:

-BLocate the executable file.

-MLocate the Help file.

-SLocate the source code file.

-USearch for executable files, source code files, and help files in the default path.

-BSpecifies the path for searching executable files.

-MSpecifies the path for searching the Help file.

-SSpecifies the path for Searching Source code files.


Whereis example:
1.Locate the executable file, source code, and man manual of the date command, and enter:
$ Whereis date
The output is as follows:
Whereis-command-demo.gif
Animated gif 01: whereis command running on my Debian based server
1.1How can I only search for the location of a binary file?
Use the-B parameter:
$ Whereis-B date
1.2How can I only search for man manual positions?
Use the-m parameter:
$ Whereis-m date
1.3How can I only search for the location of the source code file?
Use the-s parameter:
$ Whereis-s date
2.How do I limit the search path?
Use the following parameters to limit the corresponding search path:
-B/path/to/dir: Restrict searching for binary files in the specified directory.
-M/path/to/dir: Restrict searching for man manual files in the specified directory.
-S/path/to/dir: Restrict searching for binary files in the specified directory.
When any-B,-M,-S parameter is used, the-f parameter must be added and the file name to be searched must be specified.
2.1Search for ls and gcc only in the/bin directory.
$ Whereis-B/bin-f ls gcc
The result is as follows:

Gcc:/usr/share/man/man1/gcc.1.gz
Ls:/usr/share/man/man1/ls.1.gz/bin/ls
 
2.2Find all the files in the/usr/bin directory. The man file is not in the/usr/man/man1/directory, and the source code file is not in the/usr/src/directory.
# Cd/usr/bin
# Whereis-u-M/usr/man/man1-S/usr/src-f *

For the-u Parameter Function of whereis, it is difficult to find the source code of the corresponding version of whereis because you do not know the version of whereis,
Whereis Code address on git: https://github.com/karelzak/util-linux/blob/master/misc-utils/whereis.c#L96
The-u parameter is rarely used. If you are interested, you can check this code.

 

Reference: http://www.poluoluo.com/server/201502/338955.html

 

Chocoo

2016.3.9

Certificate ----------------------------------------------------------------------------------------------------------------------------------------

New Linux users are welcome.

Thank you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.