Find out path of program

5

On Unix I can call certain programs from everywhere, like sort, pwd or my_custom_script.sh.

How can I find out, where on the system my_custom_script.sh really resides?

user36938

Posted 2011-05-20T09:54:02.067

Reputation:

Answers

3

I would recommend using type command. which command only look in the PATH so can be misleading for builtins (like pwd), functions and aliases.

jlliagre

Posted 2011-05-20T09:54:02.067

Reputation: 12 469

which actually also lists aliases. – Daniel Beck – 2011-05-20T10:40:40.963

1I'm afraid it can't. which isn't a shell builtin so has no idea about internal commands/aliases and the like. – jlliagre – 2011-05-20T11:38:01.563

On my Linux box, "which" is unexpectedly aliased. Sorry about that. – Daniel Beck – 2011-05-20T12:38:04.480

8

Use which

which sort

Gives you (for example):

/usr/bin/sort

This also helps you to troubleshoot issues with your PATH, e.g. if you have several versions of the same binary installed and you don't know which one is called.

So if you have multiple versions, you can use the -a switch:

charon:~ werner$ which -a ruby
/Users/werner/.rvm/rubies/ruby-1.9.2-head/bin/ruby
/Users/werner/.rvm/bin/ruby
/usr/bin/ruby

slhck

Posted 2011-05-20T09:54:02.067

Reputation: 182 472

1which will work for my_custom_script.sh but will give misleading information about pwd and similar commands. – jlliagre – 2011-05-20T11:53:05.270