Command line tip - find out which version of a program will run

  • May 27, 2007
  • Avatar for peter
    Peter
    Upfold

On your system, it is perfectly possible that you might have more than one version of a particular application installed. If you've custom compiled an application or have concurrent versions of one bit of software, this might be an issue for you.

Now when a program is in your PATH (in one directory of a list of special directories on your system), you can execute it just by typing its name and not the full path (e.g. ls and not /bin/ls).

But what happens when you've got two programs in PATH directories called the same thing? Well, usually the order of the directories in PATH will decide which one gets executed. A really easy and quick way to work out which one will get executed, though, is to use the built-in command which.

This command is also extremely useful if you want a quick way to discover where a command is located on the filesystem, for example if you can't remember whether something is in /bin or /usr/bin.

Simply type which followed by the desired command name.

$ which ls
/bin/ls

Easy, simple and pretty memorable too. Next time you're hunting for that program's exact location or are confused about which program is which, use which.

Avatar for peter Peter Upfold

Home » Articles »