Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I frequently find myself SSHing into various OS X machines, and it'd be useful if I could tell what version of OS X I was on when I'm doing that. uname -a doesn't quite work, since Darwin kernel versions don't always change with the rest of the system.

share|improve this question
up vote 42 down vote accepted

The answer that suggested system_profiler | grep 'System Version' is what I have tried to use in the past, but it has 2 problems.

  1. It is slow since it generates a full system_profiler dump of the machine, gathering all hardware and software inventory information.
  2. The output of system_profiler has changed over time. e.g. output of grep for '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.

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
share|improve this answer
    
I'd flip this around. ``` Use sw_vers … --------------------------- The answer that suggested system_profiler… ``` – Tim Visher Nov 30 '15 at 15:09

The easiest way is:

$ sw_vers -productVersion
10.6.4

From http://tinyapps.org/blog/mac/201008140700_os_x_version_terminal.html:

$ 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.

share|improve this answer
1  
This should be the accepted answer. – Walrus the Cat Dec 24 '14 at 12:24

Try this:

 system_profiler  | grep 'System Version'
share|improve this answer
3  
what Mike Gray said. – hop Aug 18 '10 at 17:05

Here is a Blog article with instructions How to Get the Mac OS X Version in a Shell Script

OS_VERSION=`/usr/bin/defaults read "$3/System/Library/CoreServices/SystemVersion" ProductVersion`
echo "$OS_VERSION"
share|improve this answer
    
This is very useful for finding the version of a non-active operating system, eg. a volume that is being repaired or such. – ylluminate Aug 4 '15 at 22:29

Open Terminal.app

$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.6.4
BuildVersion:   10F569
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.