How does one find the command path in linux?

Source: Internet
Author: User

How does one find the command path in linux?

In linux, we often use commands such as cd, grep, and vi. Sometimes we need to find the location of these commands. How can we do this?

In linux, there are two commands to complete this function:Which, whereis

Which is used to view when

The path of the command to be executed.

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

 

 

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 to say, by using the which command, you can see whether a system command exists and where the command is executed.

Use instance of the which command:

$ Which grep

 

 

Whereis command principle: it 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) are searched ). If the parameter is omitted, all information is returned.

Examples of using the whereis command:

$ Whereis grep

 

The following is an example. Added multiple versions of java to your linux system. If you directly press "java-version" on the command line, you will get a result. However, do you know which path of java is being executed? If you want to know, you can use the which command:

Which java

The returned result is the first JAVA location in the PATH, that is, the default JAVA Command Execution location.

If you use the command: whereis java

You will get a lot of results, because this command lists all the paths containing java (files or folders.

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.