How to find out Mac OS X version from Terminal?

You have a few options:

sw_vers -productVersion 

system_profiler SPSoftwareDataType

Either will do what you need, and will have an output format that's parseable (if that's what you're after).


The command sw_vers shows the version.

For older Mac OS's you can find useful information in Wikipedia.


If all you care about is the major version (10.10, 10.9), you can do

MAJOR_MAC_VERSION=$(sw_vers -productVersion | awk -F '.' '{print $1 "." $2}')

I use this in a couple of scripts that have to do different things if run on 10.8.x, 10.9.x and now 10.10.