SoFunction
Updated on 2025-03-04

How to query binary file location through commands for Linux

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

whichThe command mainly locates the location of the binary executable file, which isPATHSearch 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

whereisCommands 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.

andwhichMore extensive searches than providing searches, including source code and manual files

Use the locate command

locateIt 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

findCompared with other commands, it is slower

Use the type command

typeCommands 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 -vReturns the path or its alias for the command in the shell.

usage

command -v <command>

Example

command -v ssh
# Output: /usr/bin/ssh

command -vandwhichSimilar, the difference is that it is a built-in command in the shell

Use the readlink command

readlinkThe command resolves the symbolic link to its target path.

usage

readlink -f $(which <command>)

Example

readlink -f $(which ssh)
# Output: /usr/bin/ssh

readlinkThe 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!