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