What version of RHEL am I using?

You can use the lsb_release command on various Linux distributions:

lsb_release -i -r 

This will tell you the Distribution and Version and is a little bit more accurate than accessing files that may or may not have been modified by the admin or a software package. As well as working across multiple distros.

For RHEL, you should use:

cat /etc/redhat-release

You can look at the contents of /etc/redhat-release, which will look something like this:

$ cat /etc/redhat-release 
CentOS release 5.4 (Final)

The contents are different for an actual RHEL system. This technique works on all RedHat derivatives, including CentOS, Fedora, and others.


I prefer to use the /etc/issue file.

$ cat /etc/issue

I've seen many situations where /etc/redhat-release has been modified to meet software compatibility requirements (Dell or HP's management agents, for instance).


The most reliable way when lsb_release is not installed is:

# rpm -q --queryformat '%{VERSION}' redhat-release-server
6Server

# rpm -q --queryformat '%{RELEASE}' redhat-release-server
6.4.0.4.el6

On minimal installs, lsb_release is missing.

To get this working also with Red Hat clones (credit goes to comments):

# rpm -q --queryformat '%{VERSION}' $(rpm -qa '(redhat|sl|slf|centos|oraclelinux)-release(|-server|-workstation|-client|-computenode)')

Or, as a single command (rather than two "rpm"'s being executed):

# rpm -qa --queryformat '%{VERSION}\n' '(redhat|sl|slf|centos|oraclelinux)-release(|-server|-workstation|-client|-computenode)'

Use sed/cut and other text manipulating UNIX tools to get what you want.