tags:

views:

703

answers:

3

In Windows I read the registry key SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName to get the full name and version of the OS.

But in Linux, the code

struct utsname ver;
uname(&ver);
retVal = ver.sysname;

returns the string linux, not Ubuntu 9.04.

How can I get the Linux distribution name and version?

A: 

Usually:

cat /etc/issue
/etc/issue is what is displayed on a terminal before you log in. Reading the file itself would normally give you something like "This is \n.\O (\s \m \r) \t ". Not very useful! It's a piece of freeform text which could contain anything in other words.
Chris Huang-Leaver
+3  A: 

Not sure I followed exactly what your after but I think you just want the "all" flag on uname:

uname -a
Shaun
Unfortunately, on Fedora 11 output of "uname -a" if Linux localhost.localdomain 2.6.29.6-217.2.8.fc11.i586 #1 SMP Sat Aug 15 00:44:39 EDT 2009 i686 i686 i386 GNU/Linux
Dmitriy
+16  A: 

Try:

cat /etc/lsb-release

You can also try

lsb_release -a

Or:

cat /proc/version
thekidder
+1 this finally was "standardized" among the distro's. Go back far enough though and this file doesn't exist, instead each distro put their own file like /etc/redhat-release.
KFro
lsb_release -a works well, thaks
Dmitriy
This will only work on LSB compliant Linux distributions, but is not guaranteed to work on non-compliant distributions. OTOH, it will also work on *other* LSB compliant non-Linux Unices. E.g. I'm pretty sure it won't work on Adroid.
Jörg W Mittag