How to detect linux distribution and version?

I want to detect linux distribution and version.

I searched with my favorite search engine and discovered lsb_release.

Unfortunately this tool is not installed by default.

I would like to avoid to install lsb_release first.

Is there no easier way to detect the linux distribution and version in a portable way?

With "portable" I mean different kind of linux distributions. Not *BSD or Windows.


cat /etc/*-release should do the trick

Docs: https://www.freedesktop.org/software/systemd/man/os-release.html


Pick one...

cat /etc/issue
source /etc/os-release && echo "$NAME $VERSION"
cat /etc/os-release
uname -a

I guess most modern and LSB compliant distributions should provide /etc/os-release, but as usual: it's complicated! ;-)

Some further reading material:

https://en.wikipedia.org/wiki/Linux_Standard_Base

http://0pointer.de/blog/projects/os-release.html