Thursday, September 20, 2007

Witchy which linux command

Here's a simple linux command the give you the full path of of linux binary or executable command.

Which definition:
~~~~~~~~~~~~~~~~~~

Which Linux command shows the full path of any binary or shell command when executed. Which does the full patch searching by looking from the linux environment PATH variable. Which command can take one or more argument for processing. This 'which' linux comamnd follows the command line format as shown below:

which command1 command2


To list out your PATH environment variable from command line

# echo $PATH

Alternatively, you can grep PATH variable from your current environment shell like so

# set | grep PATH


Which Usage
~~~~~~~~~~~

Let us assume that you have a command named fixit that was installed from tar ball (tar.gz) and from rpm package (rpm). On which, fixit was probably installed into /usr/bin and /usr/local/bin .

To execute the command, simply issue

# fixit

The problem with this command is you don't know which binary has been executed by the system.
One way of resolving this issue is using which linux command by doing so

# which fixit

which then tells you which binary would be executed if fixit was issued from ther terminal. Which linux command also tells your the full path location of the command argument.

Final Which Note:
~~~~~~~~~~~~~~~~~

Using which, you can then know where would be the binary path location is when a command or executable shell would be executed. Which linux command is installed in Fedora by default system tools installation.

More which command line examples:
~~~~~~~~~~~~~~~~~~~~

# cd /home/me
# chmod 700 fixme
# which ./fixme
~~~~~~~~~~~~~~
/home/me/fixme
~~~~~~~~~~~~~~

# which which
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
/usr/bin/which
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# cd /tmp
# touch cat
# chmod 700 cat
# which ./cat
~~~~~~~~~~~~~~~~~~
/bin/cat
~~~~~~~~~~~~~~~~~~

# which echo dir
~~~~~~~~~~~~~~~~~~~~~~~~~~~
/bin/echo
/usr/bin/dir
~~~~~~~~~~~~~~~~~~~~~~~~~~~


HTH

0 comments:

Sign up for PayPal and start accepting credit card payments instantly.
ILoveTux - howtos and news | About | Contact | TOS | Policy