Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find all copies of an executable name in my PATH?

Tags:

bash

path

I was looking for a way to enumerate all copies of an executable that are shadowed by the first one in my PATH. The best I could come up with is a function:

find_all_exec() {      for i in ${PATH//:/ }; do         find "$i/$1" 2> /dev/null     done }  $ find_all_exec python /usr/local/bin/python /usr/bin/python 

This gets me what I want (though it doesn't handle bash aliases/functions as type does). I was curious if there's a more built in way?

like image 474
weaver Avatar asked Aug 01 '13 16:08

weaver


People also ask

Where does Linux look for executables?

In Linux, PATH is an environmental variable that tells the shell and other programs which directories to search for executable files. It consists of a list of colon-separated absolute paths to directories containing the executables.

How does Linux search path?

The search path is a list of directories that may contain programs the user wants to run. When the user types the name of a command (program), the directories in the search path are examined to see whether they contain an executable with the requested name. As soon as an executable is found, that program in executed.


1 Answers

Try this builtin command:

which -a python 
like image 135
Lorenzo Marcon Avatar answered Sep 17 '22 13:09

Lorenzo Marcon