Is there any way to find out which Linux Distribut

2019-05-17 00:11发布

问题:

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 ....

回答1:

cat /etc/lsb-release

root@pierr-desktop:~# cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=8.10
DISTRIB_CODENAME=intrepid
DISTRIB_DESCRIPTION="Ubuntu 8.10"


回答2:

lsb_release -a might help on debian and apparented.



回答3:

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.



回答4:

You could give

cat /etc/issue

a try too



回答5:

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.



回答6:

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



回答7:

try with cat:

cat /proc/version

but with uname is maybe better:

uname -a