Nov 16, 2011

How to check Linux distribution version

Do you know how to check Linux distribution version by a shell command?

In Linux, the most common command to show current version is "uname-r" to check the kernel version:

[jackieyeh@dhcppc15 ~]$ uname -r
2.6.18-6-686
[jackieyeh@dhcppc15 ~]$

What if you'd like to know the distribution version in stead of kernel version?

Since there are some many "flavors" in Linux, the Linux version is distinguished not only by kernel version, but also distribution versions, like Fedora, Debian, Ubuntu, etc...

Here is the summary of the ways to get the distribution version. Although different distributions may have slight difference, luckily you can get the answers with couple trials.


  • 1. cat /proc/version

By typing "cat /proc/version", you'll get similar results as "uname", but it's more complete. This is a generic command for every distribution, you may or may not get the distribution information, but anyway you can get some "clues". Below are 2 examples of Fedora and Debian:
Fedora:
[jackieyeh@vega ~]$ cat /proc/version
Linux version 2.6.23.17-88.fc7 (mockbuild@xenbuilder2.fedora.redhat.com) (gcc version 4.1.2 20070925 (Red Hat 4.1.2-27)) #1 SMP Thu May 15 00:35:10 EDT 2008
[jackieyeh@vega ~]$
Debian:
packetship:~# cat /proc/version
Linux version 2.6.18-6-686 (Debian 2.6.18.dfsg.1-24etch2) (dannf@debian.org) (gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)) #1 SMP Tue May 5 00:40:20 UTC 2009
packetship:~#

  • 2. cat /etc/*-release

By typing "cat /etc/*-release", you may get the distribution version. The "*" is a wild-card character as we don't know the exact versions (that's what we try to get, remember?). This command is effective on Fedora and Ubuntu. Below is an example of Fedora.
Fedora:
[jackieyeh@vega src]$ cat /etc/*-release
Fedora release 7 (Moonshine)
Fedora release 7 (Moonshine)
[jackieyeh@vega src]$
  • 3. cat /etc/issue

By tying "cat /etc/issue", you can always get the result -- This is effective for every distribution since it's a standard file for Linux system and always there. Normally this file will show distribution version by default. However this file is usually edited by the system administrator to show welcome message when a user log in the system -- therefore the distribution version may be removed.
Below are 2 examples of Fedora and Debian:
Fedora:
[jackieyeh@vega ~]$ cat /etc/issue
Fedora release 7 (Moonshine)
Kernel \r on an \m

[jackieyeh@vega ~]$

Debian:
packetship:~# cat /etc/issue
Debian GNU/Linux 4.0 \n \l

packetship:~#
  • 4. cat /etc/debian_version

Obviously, typing "cat /etc/debian_version" is exclusively for Debian. It will show Debian distribution version without any problem.
Debian:
packetship:~# cat /etc/debian_version
4.0
packetship:~#
Summary:
Generally speaking, by typing "cat /etc/issue" normally you can get your answers. And it's effective cross every distribution, so it should be your first choice. Once it's modified by the system administrator and prevent you from getting the answer, then you can try other ways as suggested above.

No comments:

Post a Comment