My suggestion is to use
sw_vers. Example output as of 10.6.4:
> sw_vers ProductName: Mac OS X ProductVersion: 10.6.4 BuildVersion: 10F569
The answer that suggested
system_profiler | grep 'System Version' is what I have tried to use in the past, but it has 2 problems.
- It is slow since it generates a full system_profiler dump of the machine, gathering all hardware and software inventory information.
- The output of system_profiler has changed over time. e.g. output of
grepfor ‘Serial Number’ on 10.6.4 is “Serial Number (system): ZNNNNNZNZZZ”, whereas on 10.4.11 it was “Serial Number: ZNNNNZNZZZZ” – importance being the parse-ability of the output and the add ” (system)” piece can be problematic unless you are expecting the change.
The easiest way is:
$ sw_vers -productVersion 10.6.4
$ sw_vers ProductName: Mac OS X ProductVersion: 10.6.4 BuildVersion: 10F569 $ sw_vers -productVersion 10.6.4
Especially handy when resetting a password in single user mode, since the method varies based on which version of OS X is running.
system_profiler | grep 'System Version'
Mike Gray’s answer is better than this. Please see that