Linux – How to tell whether the system is Unix or Linux

linux

How can I tell whether my system is Unix or Linux?

I am using a Macbook Pro of 2010 vintage.

Best Answer

POSIX defines uname ("Unix name") to provide information about the operating system and hardware platform; running uname gives the name of the implementation of the operating system (or according to the coreutils documentation, the kernel). You can do this interactively in a terminal, or use the output in a script.

On Linux systems, uname will print Linux.

On Mac OS X systems, uname will print Darwin. (Strictly speaking, any operating system with a Darwin kernel will produce this, but you're very unlikely to encounter anything other than Mac OS X in this case.)

This will allow you to determine what any Mac is running. As Rob points out, if you're running Mac OS X (Darwin as indicated by uname), then you're running a certified version of Unix; if you're running Linux then you're not.

On a Mac there are many other possibilities; your script could end up running on Solaris (uname will print SunOS then), on FreeBSD (FreeBSD), on Windows with Cygwin (CYGWIN), MSYS or MSYS2 (MSYS), a MinGW or MinGW-w64 shell (MINGW64, MINGW32), Interix (Interix), and probably others I'm not aware of.

uname -a will print all the available information as determined by uname, but it's harder to parse.

Related Question