1

In Red Hat the file /etc/redhat-release contains the operating system version data (such as "Red Hat release X.X (Final)").

Is there any similar mechanism in Mac OS X that can be used programatically to get the operating system version data (such as "Mac OS X 10.5.8")?

Chealion
  • 5,733
  • 28
  • 29
knorv
  • 1,799
  • 6
  • 19
  • 29

2 Answers2

4

In case you are looking for more details to the kernel, you can also query the sysctl interface which provides the kernel ostype, version and other details.

  • To get the ostype : sysctl kern.ostype
  • To get the osversion : sysctl kern.osversion
  • To get the version : sysctl kern.version
  • To get the osrevision : sysctl kern.osrevision

More details here : http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man8/sysctl.8.html

vivekian2
  • 538
  • 3
  • 8
  • 13
  • 1
    Just FYI: On Ubuntu, it's "kernel" instead of "kern". And for these keys, the output is the same as `uname -a` (or the various subsets from other options like `-s`, `-r`, `-v`, etc.) – Dennis Williamson Sep 06 '09 at 22:01
  • 1
    `uname -a` on a Mac: "Darwin .local 9.8.0 Darwin Kernel Version 9.8.0: Wed Jul 15 16:55:01 PDT 2009; root:xnu-1228.15.4~1/RELEASE_I386 i386" – warren Sep 07 '09 at 03:21
  • none of those give the OS version he wanted, e.g. 10.5.8. They give the kernel version numbers. – malhal Nov 14 '16 at 00:57
2

Found the answer:

/usr/bin/sw_vers
knorv
  • 1,799
  • 6
  • 19
  • 29