2

How to get the location of a program in Ubuntu? For example I have Oracle, how to get the folder racine (location) of Oracle?

6

You can also use whereis. It will show the path to the binary but also some related files like documentation:

whereis program

| improve this answer | |
8

Bash and Dash have the command built-in command that can show you the location of a command with the -v switch, if the command refers to an executable. For built-in commands and aliases the result is different. Examples:

$ command -v java
/usr/bin/java
$ echo $?
0
$ command -v echo
echo
$ command -v ls
alias ls='ls -h --color=auto'
$ command -v non-existing_command; echo $?
1

Additionally, all shells derived from Sh, know the type command that tells you about the nature of any command.

$ type java
java is /usr/bin/java
$ type ls
ls is aliased to `ls -h --color=auto'
$ type echo
echo is a shell builtin
$ type non-existing_command
bash: type: non-existing_command: not found

If your shell (e. g. Bash) supports it, type -a lists everything that a command may refer to:

$ type -a ls
ls is aliased to `ls -h --color=auto'
ls is /bin/ls
$ type -a echo
echo is a shell builtin
echo is /bin/echo
$ type -a touch
touch is /usr/bin/touch
touch is /bin/touch
| improve this answer | |
  • +1 Not all Bourne-style shells support a -a option for type though. For example, in dash the -a is treated as another name of a command to look up (and will typically not be found). – Eliah Kagan Oct 5 '17 at 23:10
  • +1. Didn't notice you had type -a in your answer until after I posted mine. I revised my answer giving you credit for mentioning it already :) – WinEunuuchs2Unix Jul 1 '18 at 23:23
7

You can use which to determine which binary is being run.

  • which ssh
  • which Oracle

These are examples and would return the full path for the binaries.

You could also use whereis to locate additional information, but it may confuse you in this situation.

| improve this answer | |
1

As David Foerster already mentioned, you can use type -a which will show all the locations a given executable can be found in the active $PATH:

$ type -a now
now is /home/rick/bin/now
now is /mnt/e/bin/now

type -a will also identify if the command is a shell built-in. For example:

$ type -a test
test is a shell builtin
test is /usr/bin/test

type -a will also identify if the command is a shell keyword. For example:

$ type -a if
if is a shell keyword

type a lists programs, commands, shell built-ins and shell keywords in the hierarchal order they would be called depending on the $PATH environment variable. By changing PATH= to a different order it changes which version of the program is called. This is handy when you have production, development and test program versions on the same machine.

Program isn't in $PATH

What if the program isn't in your path? The fastest way of finding it is with the locate command:

$ locate .bashrc
/etc/bash.bashrc
/etc/skel/.bashrc
/home/rick/.bashrc
/home/rick/.bashrc~
/mnt/e/.bashrc
/mnt/e/Temporary Work/.bashrc
/usr/share/base-files/dot.bashrc
/usr/share/doc/adduser/examples/adduser.local.conf.examples/bash.bashrc
/usr/share/doc/adduser/examples/adduser.local.conf.examples/skel/dot.bashrc

I kind of cheated here because .bashrc isn't a real executable, it's a "source" file to include in a bash script which is an executable. However it serves to illustrate appropriately.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.