Query what Linux/Unix distribution you're using (from the command-line)

8

1

When using an unfamiliar Linux/BSD/Unix computer (e.g. by SSH) from the command line, how can you tell what distribution (and what version of that distribution) you're using?

Some options I've tried:

  • lsb_release --all: doesn't exist on OpenSuSE 11.3; works on Debian squeeze and Ubuntu 10.10.
  • uname --all: doesn't give distro information on SuSE and Debian; works in Ubuntu.
  • cat /etc/apt/sources.list in you can see which distribution's servers the machine connects to for updates. Obviously, only works for Debian-based distributions. Won't work if the computer has been configured to use a custom repository server.

Unfortunately none of these seem to work across many distributions. Is there a simple command to check?

Mechanical snail

Posted 2011-10-19T07:25:26.153

Reputation: 6 625

Question was closed 2014-01-10T15:48:24.160

Answers

11

If Python 2.3 or later is installed, this will work with many distributions:

python -c "import platform; print platform.dist()"

Patches

Posted 2011-10-19T07:25:26.153

Reputation: 14 078

10

cat /proc/version

might do the trick.

Journeyman Geek

Posted 2011-10-19T07:25:26.153

Reputation: 119 122

3There are many unixes that don't support the /proc pseudo-filesystem. – dmckee --- ex-moderator kitten – 2011-10-19T16:08:12.547

1

There is no one magic command that works across all distributions - you will need to try a series of things to work out an answer.

Things to try include some you have done, like lsb_release, and others that you haven't like looking at /etc/redhat-release, /etc/fedora-release, etc.

TomH

Posted 2011-10-19T07:25:26.153

Reputation: 2 558

Also /etc/SuSE-release. – Mechanical snail – 2011-10-19T07:46:48.420

1Check /etc/*-release -- but there are systems with no such file(s). – Keith Thompson – 2011-10-19T09:01:15.180