Is there any way to find out which Linux Distribut

2019-05-16 23:45发布

I would like to show the user some help on specific operations in my program of the form:

Please type "apt-get install foobar" to install the foobar feature.

Is there anything to do this or do i have to leave it to the user and offer a dozend choices from Red Hat, Suse, Debian/Ubuntu, Mandriva, Slackware, Gentoo ....

7条回答
Evening l夕情丶
2楼-- · 2019-05-17 00:04

No, there is no generic way to find out which Linux distribution you are running on.

There is the lsb_release command, which is specified in the Linux Standard Base specification. But obviously this command is only present on LSB-compliant distributions, and many smaller or specialized distributions are not LSB-compliant. (For example, the distribution I am running on my FritzBox router is not.)

And if you are assuming an LSB-compliant distribution anyway, then why not simply package your application as an LSB package? That way it works the same on all LSB-compliant distributions.

查看更多
何必那么认真
3楼-- · 2019-05-17 00:13

lsb_release -a might help on debian and apparented.

查看更多
来,给爷笑一个
4楼-- · 2019-05-17 00:13

Given that Linux can be built starting with one system and morphed into another, you may not be able to tell precisely which it currently is. Some distribution provide the lsb tools if they are LSB compliant, so that might help.

Some distributions provide a file /etc/dist-release. For example, I have a file /etc/arch-release that is empty.

You might also execute:

uname -a

That might indicate the the distribution the kernel was built for, but that might be a long shot. My Arch linux kernel has no mention of Arch, but I believe my Gentoo install indicates "Gentoo Linux".

Some tools can be indicative of the distribution, such as apt-get, rpm, emerge, but you can usually install those tools on other distributions as well.

查看更多
Evening l夕情丶
5楼-- · 2019-05-17 00:17

You could give

cat /etc/issue

a try too

查看更多
Melony?
6楼-- · 2019-05-17 00:17

try with cat:

cat /proc/version

but with uname is maybe better:

uname -a
查看更多
等我变得足够好
7楼-- · 2019-05-17 00:20

You can do it for most well know distros(Redhat, Fedaora, Gentoo, Suse, Debian, Ubuntu), those have special files to identify the distribution and version. i.e. /etc/debian_version.

But it would be a tedious task for you to list out all the package and things but if you really want to be user friendly

查看更多
登录 后发表回答