c++clinux

How to get Linux distribution name and version?


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?


Solution

  • Try:

    cat /etc/lsb-release
    

    You can also try

    lsb_release -a
    

    Or:

    cat /proc/version