Usha Guduri

Unix in Simple English: whatis-whereis-locate-which

Each application/program over time, as it evolves (hopefully for the better!), is released in several versions. Ever wondered which version is being used or where/what all the versions installed are? Its quite easy with just using simple english in unix!

Lets start with a quick snippet on what an executable is with ‘whatis’. It searches for whole words within the whatis database that contains short descriptions of system commands.

$ whatis ruby
irb(1), erb(1), ri(1), rdoc(1), testrb(1) - Ruby helper programs
ruby(1)                  - Interpreted object-oriented scripting language

Now ‘whereis’ does the job of indicating where the specified executable is.

$ whereis ruby

However, note that ‘whereis’ only “checks the standard binary directories” like /bin, /sbin, /usr/bin. To locate all different variations of the file ‘ruby’, irrespective of where they are installed, we’d use ‘locate’ like so:

$ locate ruby

This lists all matches in the filename including the full path for the given pattern. The database is pre-computed with `locatedb’ and re-computed periodically. An alternative is to use the ‘find’ command for more real-time results using tree search.

And finally with all the different versions installed, which one is being used when you run ‘ruby’?

$ which ruby

Since I changed the ruby version with rvm to 1.9.3, its showing the 1.9.3 executable. If I switched it back to the default, it would now look like this:

  $ which ruby

‘which’ looks for the executable within the user’s path. Now how the user’s path is determined will be left for another post!