The difference between Whereis command usage and which in Linux

Source: Internet
Author: User
Tags manual svn

Whereis syntax

Whereis [-S] [-b] [-M] [u] [{{s |-B |-m} Directory ...} ...-f] the filename to look for.

Supplemental Note: The WHEREIS directive looks for eligible files in a specific directory. The properties of these files should belong to the original code, binary file, or help file.

Describe

The Whereis command finds the source, binary files, and manuals for the specified file. The name provided first removes the leading path name component and any (single) trailing extensions (for example,. c) formatted as. ext. The S. prefix caused by the use of the source control system (see SCCS) is also processed. The command then attempts to find the desired program from a list of standard locations.
If you enter the wrong option, a usage message is returned. In other cases, diagnostics are not provided.
Sign

If any of the-B, S, M, or-u flags are given, the Whereis command searches only for binary files, sources, manuals, or unusual portions (or two of them, respectively).
-B searches the binary portion of the file.
-M to search the manual section of the file.
-S to search for the source part of the file.
-U no documents documented
The-B,-M, and-s flags can be used to change or limit the location of the Whereis command search. Because the program uses the ChDir subroutine to run faster, the pathname given in the-M, s, and-B flags directory list must be complete, for example, they must start with a/(slash).

-B is the same as-B, but adds a directory to search for. Change or restrict the location of the Whereis command to search for binaries.
-M is the same as-m but added the directory to search for. Change or qualify the location of the Whereis command Search Manual section.
-S is the same as-s, but adds a directory to search for. Change or qualify the location of the Whereis command search source.
-F terminates the last-M, s, or-B directory list concurrent filename start position signal.

Example

Finding a program in linux can be searched with the Whereis command.

Like looking for my.cnf

Entering at the command line

Whereis my.cnf

It will show the directory where the file is located.

Example 2: Find files related to * * * files

Command:
Whereis SVN
Output:
[Root@localhost ~]# Whereis Tomcat
Tomcat:
[Root@localhost ~]# Whereis SVN
SVN:/usr/bin/svn/usr/local/svn/usr/share/man/man1/svn.1.gz
Description
Tomcat is not installed, can not find out, SVN installation found a lot of related files

Instance 3: Only binary files are found

Command:
Whereis-b SVN
Output:
[Root@localhost ~]# Whereis-b SVN
SVN:/USR/BIN/SVN/USR/LOCAL/SVN
[Root@localhost ~]# whereis-m SVN
SVN:/usr/share/man/man1/svn.1.gz
[Root@localhost ~]# whereis-s SVN
Svn:
[Root@localhost ~]#
Description
Whereis-m SVN found the documentation path, Whereis-s svn find source file.

Add: which differs from Whereis command

Feature Description: Find files.
Syntax: which [file ...]
Supplemental Note: The which directive will look for eligible files in the directory of environment variable $path settings.
Parameters
-n< file name length > Specify a filename length that must be greater than or equal to the longest file name in all files.
The-p< filename length > is the same as the-n parameter, but the < filename length here > includes the path to the file.
-W Specifies the width of the field when output.
-V Display version information

1, which

Grammar:
[Root@redhat ~]# which executable file name
For example:
[Root@redhat ~]# which passwd
/usr/bin/passwd
Which is looking for executables through the PATH environment variable, so the basic function is to find executable files

2, Whereis

Grammar:
[Root@redhat ~]# Whereis [-bmsu] file or directory name
Parameter description:
-B: Only binary files are found
-M: Only files found under the manual path of the description file
-S: source source files only
-U: No documents are documented
For example:
[Root@redhat ~]# Whereis passwd
passwd:/usr/bin/passwd/etc/passwd/usr/share/man/man1/passwd.1.gz/usr/share/man/man5/passwd.5.gz
Find files that are related to passwd files

[Root@redhat ~]# whereis-b passwd
passwd:/usr/bin/passwd/etc/passwd

Find only binary files

Whereis lookups are very fast compared to find, because the Linux system records all the files in the system in a database file, and when you use the Whereis and the locate that are described below, you look up data from the database rather than the Find command , by traversing hard disk to find, the efficiency will be very high.
But the database file is not a live update and is updated once a week by default, so when we use Whereis and locate to find the file, we sometimes find the data that has been deleted, or we just set up the file, but we can't find it, because the database file is not updated

Related Article

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.