How to Display the Path of an Executable File in Linux


Want to display the path of an executable Linux file? Several Linux commands, such as which, whereis, type -a, and command -v, can help you locate executable files and understand their origins in a simple and effective way.

Displaying the path of executable Linux files is useful for troubleshooting and verifying which version of a command is being used. It helps you check which version of the command is being executed when multiple versions or installations exist on the system. For example, if you have a system-wide and a user-installed version of a program, knowing the exact path helps you avoid unexpected behavior. It is particularly useful in environments where PATH variables are customized or modified.

Related


How to Add a Directory to Your $PATH in Linux

Do not add everything to your PATH. Seriously.

Method 1: The which Command

The which command in Linux enables you to locate and display the exact path of an executable file. You can specify one or more files to find their paths. When you use the which command on Linux, it checks the directories listed in the PATH environment variable. It then shows the location of the first matching executable file it finds. However, you can run this command with the -a option to show all occurrences of an executable.

Linux’s which command returns three types of exit codes: 0 when all specified files are located and can run, 1 when at least one command is not executable, and 2 when an unrecognized option is used. The syntax for using the which command in Linux is shown below:

which -a [fileName] ...

Here, fileName represents an executable file whose path you want to locate.

Example: Locating Executables on Linux with the which Command

Let’s run the which command to find the path of an executable file, Python3.10:

which -a Python3.10

It retrieves all matching pathnames for the specified executable file:

display path of executables using which command
How-to Geek

Method 2: The whereis Command

The whereis command in Linux returns the locations of binary files (executables), source code files, and man pages for a given command. When you execute the whereis command, it browses standard system folders and shows the paths of the executable file and the manual pages related to the given command. The general structure for using the whereis command on Linux is shown below:

whereis [options] [fileName] ...

The whereis command can accept several options that are used to achieve a specific functionality. For example, you can execute whereis command with the -b option to search only binary files, -m for only manual pages, -B to specify the binary search path, and so on.

Example: Displaying the Path of an Executable With whereis

Firefox is an executable program available on Linux systems. You can use the whereis command to display its path:

whereis firefox

In the following output, “/usr/bin/firefox` represents the path to the executable:

display path of executable files using whereis
How-to Geek

Method 3: The type Command in Linux

The type command in Linux allows you to determine the nature of a command. For example, it tells whether the specified command is an alias, a built-in shell command, a function, or an external program stored on our system. You can also use the type command to check the path of a Linux executable file.

On Linux, type is a shell built-in command, and you can verify it by using:

type type
verify shell builtin type
How-to Geek

The basic syntax of the type command to show the path of an executable file is shown below:

type fileName

Example: Showing the Executable File Path with type

Let’s utilize the type command to show the path of Python, specifically python3.10:

type python3.10
display path of executable file using type command
How-to Geek

The type command returns the first executable path for the specified command. To show all matching locations, run type with the -a flag:

type -a python3.10
display all occurrences of executable using type
How-to Geek

Method 4: The command -v Command in Linux

The command -v command is a shell built-in command on Linux that retrieves the location of a command or shows whether it is available in your system’s PATH. When you run this command, it shows detailed information indicating whether the given command is an executable file, a shell builtin, an alias, or a function.

To show the full path of an executable file, use the syntax:

command -v fileName

Example: Showing Executable File Paths Using command -v

The following example uses command with the -v flag to show the path of Firefox:

command -v firefox

The output shows that Firefox is an executable located at “/usr/bin/firefox”:

display path of executable file using command v
How-to Geek

Related


How to Find Files and Folders in Linux Using the Command Line

Most peopleĀ use a graphical file manager to find files in Linux, such as Nautilus in Gnome, Dolphin in KDE, and Thunar in Xfce.


In Linux, several commands can help you find the path of an executable file. Each has its own specific use case, as discussed in this article. You can select the command that best suits your requirements to locate executable paths efficiently.

By practicing and mastering these Linux commands, you can quickly find the paths of your files and improve your workflow.



Source link

Previous articleA Skeptical Look at Grand Designs for the Future