To find out what version (and often build number as well) of OS X you’re running using the Terminal, you’ve got several options. The first and likely the most obvious (and simple) is using sw_version.

macmeta:~ user$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.7.3
BuildVersion: 11D50d

You can retrieve the specific information that you want using the following options: -productName | -productVersion | -buildVersion

macmeta:~ aoi$ sw_vers -productVersion
10.7.3

You can cat out /System/Library/CoreServices/SystemVersion.plist and eyeball the XML that comes back. In my case:

macmeta:~ user$ cat /System/Library/CoreServices/SystemVersion.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>ProductBuildVersion</key>
	<string>11D50d</string>
	<key>ProductCopyright</key>
	<string>1983-2012 Apple Inc.</string>
	<key>ProductName</key>
	<string>Mac OS X</string>
	<key>ProductUserVisibleVersion</key>
	<string>10.7.3</string>
	<key>ProductVersion</key>
	<string>10.7.3</string>
</dict>
</plist>

Or you could merely add grep -C 2 ProductVersion.

macmeta:~ user$ cat /System/Library/CoreServices/SystemVersion.plist | grep -C 2 ProductVersion
	<key>ProductUserVisibleVersion</key>
	<string>10.7.3</string>
	<key>ProductVersion</key>
	<string>10.7.3</string>

Using system_profiler SPSoftwareDataType gives you lots of information including kernel version:

macmeta:~ user$ system_profiler SPSoftwareDataType
Software:
 
    System Software Overview:
 
      System Version: Mac OS X 10.7.3 (11D50d)
      Kernel Version: Darwin 11.3.0
      Boot Volume: Macintosh HD
      Boot Mode: Normal
      Computer Name: macmeta
      User Name: USER (user)
      Secure Virtual Memory: Enabled
      64-bit Kernel and Extensions: Yes
      Time since boot: 56 minutes

Those accustomed to using ye olden *NIX uname -a will find that it only gives the Darwin kernel information.

macmeta:~ user$ uname -a
Darwin macmeta.tc.ph.cox.net 11.3.0 Darwin Kernel Version 11.3.0: Thu Jan 12 18:47:41 PST 2012; root:xnu-1699.24.23~1/RELEASE_X86_64 x86_64

And I saved the ugliest for last! osascript is a tool that can be used to run AppleScript. with the -e option, it will run a single line script that you enter. Let’s try osascript -e 'system info':

macmeta:~ user$ osascript -e 'system info'
AppleScript version:2.2.1, AppleScript Studio version:1.5.2, system version:10.7.3, short user name:aoi, long user name:AOI, user ID:501, user locale:en_US, home directory:alias Macintosh HD:Users:aoi:, boot volume:Macintosh HD, computer name:macmeta, host name:macmeta.tc.ph.cox.net, IPv4 address:192.168.11.119, primary Ethernet address:40:6c:8f:0d:48:a6, CPU type:Intel 80486, CPU speed:2300, physical memory:2048

As you can see, it brings back a ton of info, including the system version.

Know of any other ways to find the system version and build numbers of OS X? Let me know in the comments.