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

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 - http://peter.upfold.org.uk/

Peter Upfold is a technology enthusiast from the UK. Peter’s interest in Linux stems back to 2003, when curiosity got the better of him and he began using SUSE 9.0. Now he runs Linux Mint 9 on the desktop, runs a CentOS-based web server from home for his personal website and dabbles in all sorts of technology things across the Windows, Mac and open source worlds.

Home » Articles »

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

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