Try this command:
rpm -qa | grep release
for instance on my machine I get this
Answer from Tim on Stack Overflowredhat-release-workstation-6Workstation-6.4.0.4.el6.x86_64
bash - How to find out what version of RHEL I'm using? - Unix & Linux Stack Exchange
How to check Linux Redhat version command
How to check what "version" of Linux you're running
What is the future of free rhel?
Try this command:
rpm -qa | grep release
for instance on my machine I get this
redhat-release-workstation-6Workstation-6.4.0.4.el6.x86_64
If "anybody" has root access to your machine to either change /etc/redhat-release or install an alternate kernel you're most probably in bigger trouble than determining the redhat version of your system.
Just use the value pointed out by /etc/redhat-release or even better in terms of portability use the output of lsb_release as this is exactly the purpose they were made for.
With "anybody" being able to do anything with your system there is no other chance at all.
if grep -q -i "release 6" /etc/redhat-release
then
echo "running RHEL 6.x"
fi
This would be the simplest way I can think of.
You can also use the lsb_release command. If you're already certain it's RHEL, getting the major version number is:
majversion=$(lsb_release -rs | cut -f1 -d.)
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.