Introduction
Usually when executing Linux commands, if you want to view the program's binary files, source codes, and manuals in which directory, you need the following commands to assist.
Use the which command
which
The command mainly locates the location of the binary executable file, which isPATH
Search in environment variables.
usage
which <command>
Example
which ssh # Output: /usr/bin/ssh
The full path to the executable file will be printed
Use the whereis command
whereis
Commands can locate binary files, source codes, and command manuals
usage
whereis <command>
Example
whereis ssh # Output: ssh: /usr/bin/ssh /usr/share/man/man1/ssh.
andwhich
More extensive searches than providing searches, including source code and manual files
Use the locate command
locate
It uses pre-built database files to search, so the speed is very fast
usage
locate <filename>
Example
locate ssh # Output: /usr/bin/ssh, /usr/share/doc/ssh
Use the find command to search
Real-time search for the location of the command
usage
find <directory> -name <filename>
Example
find /usr -name ssh # Output: /usr/bin/ssh
find
Compared with other commands, it is slower
Use the type command
type
Commands determine how a command is interpreted in a shell (for example, is it an alias, a function, or a binary).
usage
type <command>
Example
type ssh # Output: ssh is /usr/bin/ssh
Use the command -v command
command -v
Returns the path or its alias for the command in the shell.
usage
command -v <command>
Example
command -v ssh # Output: /usr/bin/ssh
command -v
andwhich
Similar, the difference is that it is a built-in command in the shell
Use the readlink command
readlink
The command resolves the symbolic link to its target path.
usage
readlink -f $(which <command>)
Example
readlink -f $(which ssh) # Output: /usr/bin/ssh
readlink
The feature is to ensure that the real path to the command can be obtained, even if the symbolic link is provided
This is the article about how Linux can query the location of binary files through commands. For more related Linux commands, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!