How to get Linux distribution name and version?

2020-05-23 03:26发布

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?

标签: c++ c linux api
7条回答
欢心
2楼-- · 2020-05-23 04:25

Try:

cat /etc/lsb-release

You can also try

lsb_release -a

Or:

cat /proc/version
查看更多
登录 后发表回答