How can I find the binary that is executed when entering a command?

I just have installed TeX-Live 2012, but I still get

moose@pc07:~$ latex --version
pdfTeX 3.1415926-1.40.10-2.2 (TeX Live 2009/Debian)
kpathsea version 5.0.0
Copyright 2009 Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).
There is NO warranty.  Redistribution of this software is
covered by the terms of both the pdfTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the pdfTeX source.
Primary author of pdfTeX: Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).
Compiled with libpng 1.2.42; using libpng 1.2.42
Compiled with zlib 1.2.3.3; using zlib 1.2.3.3
Compiled with poppler version 0.12.4

So I've wondered if I could find out where the binary that gets executed when I enter latex --version is located. Is this possible?


Solution 1:

You can use

which latex

to find out the location of a binairy.

Solution 2:

The type command is built-in to bash (which is a standalone program).

type latex

The type command can also differentiate between shell aliases, shell functions and standalone programs if you pass the -a option: I have an alias for ls

$ type -a ls
ls is aliased to `ls -F'
ls is /bin/ls

Solution 3:

For simple stand-alone commands the above answers are perfectly correct. However, if you are running complex scripts and you want to know what's happening behind the scenes, the best way is always:

ps afxu

that displays the entire tree of command being executed.

For example, running ps afxu while updating grub2 with os-prober enabled produces this output:

root      4304  0.0  0.0  27308  1700 ?        Ss   16:33   0:00 SCREEN -S update-grub
root      4305  0.9  0.1  23540  4648 pts/2    Ss   16:33   0:00  \_ /bin/bash
root      4371  0.0  0.0   4392   744 pts/2    S+   16:33   0:00      \_ /bin/sh /usr/sbin/grub-mkconfig -o /boot/grub/grub.cfg
root      5127  0.0  0.0   4396   756 pts/2    S+   16:33   0:00          \_ /bin/sh /etc/grub.d/30_os-prober
root      7029  0.0  0.0   4396   176 pts/2    S+   16:33   0:00              \_ /bin/sh /etc/grub.d/30_os-prober
root      7030  0.0  0.0   4396   464 pts/2    S+   16:33   0:00                  \_ /bin/sh /etc/grub.d/30_os-prober
root      7038  0.0  0.1  23660  4676 pts/2    D+   16:33   0:00                  |   \_ /usr/sbin/grub-probe --device /dev/sdb3 --target=fs_uuid
root      7031  0.0  0.0  11520   828 pts/2    S+   16:33   0:00                  \_ sed -e s/^/\t/

In this way you can know exactly what is being called by an executable/script in each phase of its execution.