Get your linux distribution
Sometime your scripts require to know on which linux distribution they're running.
Thanks to the platform
module of python, you can, easily, get this information:
python -c 'import platform; print platform.linux_distribution()[0]'
WARN: By default, the method is limited to a set of distributions. To support more distributions, you have to overwrite this list as follow:
python -c 'import platform; print platform.linux_distribution(supported_dists=(<my set of distribution>))[0]'
Written by Sébastien Quioc
Related protips
7 Responses
does not work everywhere
Usually, I do
$cat /etc/*release
But it does not work for debian systems. It seems that you would need to do:
$ cat /etc/debian_version
6.0.7
@antigluk the method seems to read /etc/lsb-release according to this stackoverflow thread. which distribution do you use?
@squioc on arch-linux (manjaro distribution). /etc/lsb-release exists, it contains
DISTRIB_ID=ManjaroLinux
DISTRIB_RELEASE=0.8.5
DISTRIB_CODENAME=Ascella
DISTRIB_DESCRIPTION="Manjaro Linux"
but platform.linux_distribution() returns
('', '', '')
@antigluk Done. By default, the method is limited to a set of distributions. To support more distributions (or others distributions), you have to overwrite this list. I will edit the tip to add a note.
@squioc hmm. interesting. but why this limitation is exists at all?
@antigluk No ideas. This limitation exists since the initial commit of the module in 2003.