-1

On Linux and other Unix-likes, how do I find the path to a specific file that I can use because of the PATH environment variable? For example, if I can use, from the command line:

ls # technically the file name is "ls.exe"

is there a way I can find the path of the ls.exe file explicitly without looking through the PATH variable myself (i.e. maybe have a program search through it but not look myself)?

I understand there are many pitfalls/caveats of doing this, for example a PATH can be a file or even part of a file (I think), plus symlinks, etc. could make it unreliable, but I'm looking for general use cases.

The reason I am asking is I have Windows with msysgit so I have A LOT of folders in my path, and searching every one would be annoying & time-consuming, not to mention harder because of Windows limitations, but I can still presumably use almost anything Linux can use.

trysis
  • 8,086
  • 17
  • 51
  • 80

1 Answers1

1
   $ type ls.exe
   ls.exe is /usr/bin/ls.exe
inselberg
  • 549
  • 3
  • 13
  • 27
  • Thanks. Didn't realize it would be this easy. Does this work for all environment variables or just PATH? – trysis Feb 14 '14 at 07:47
  • By the way, this works whether you include the extension or not, i.e., whether you say `type ls` or `type ls.exe`. I'm sure you knew that, just throwing it out there for people reading this who don't know. – trysis Feb 14 '14 at 07:49
  • Why does this work? Where is the `type` file in the computer? I could just search, but I'm asking for the benefit of others who come to this page. – trysis Feb 24 '14 at 19:21
  • $ "type type" ... "type is a shell builtin" – inselberg Feb 25 '14 at 09:27