How Linux finds the path to a command

Source: Internet
Author: User

Linux, we often use CD, Grep,vi and other commands, and sometimes we have to find out where these commands are, how to do it?

Linux has 2 commands to complete this function:which, Whereis

Which is used to view when

The path to the command to execute before.

Whereis is used to view a command or the path of a file.

The principle of the which command: in the path specified by the path variable, search for the location of a system command and return the first search result. That is, with the which command, you can see whether a system command exists, and the command that executes exactly which location.

Examples of use of the which command:

$ which grep



Whereis command principle: only search for program name, and only binary file (parameter-B), man description file (parameter-m) and source code file (parameter-s). If the argument is omitted, all information is returned.

Examples of use of the Whereis command:

$ whereis grep


Here is an example to illustrate. Join your Linux system with multiple versions of Java installed. If you knock the command "java-version" directly at the command line, you will get a result. But, do you know which path Java is executing? If you want to know, you can use the which command:

which Java

Returns the location of the first Java in the path, where the Java command is executed by default

If you use the command: Whereis Java

Then you will get a lot of results because this command lists all the paths that contain Java (whether files or folders).


This article is from the "Dream to Reality" blog, please be sure to keep this source http://lookingdream.blog.51cto.com/5177800/1850660

How Linux finds the path to a command

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.