What is my CentOS/RedHat/Fedora Linux Distribution Name and Version


There are many way find the Linux Distribution Name and Version, but my favorite to find  CentOS/RedHat/Fedora distribution name and version is to read from /etc/redhat-release file.

redhat-release

In CentOS 6.5, /etc/redhat-release file contain following contents:

# cat /etc/redhat-release
CentOS release 6.5 (Final

To find out distribution name, use command:

awk '{print $1}' /etc/redhat-release

And to find out distribution version, use command:

awk '{print $3}' /etc/redhat-release

Use Following script, to get distribution name and version:

RELFILE="/etc/redhat-release"
# Function to check my Linux release
my_release()
{
    arg="$1"
    if [ ! -e "$RELFILE" ]; then
        echo -e "Error!!! Linux OS release not supported."
        exit 1
    fi
    
    if [ "$arg" = "name" ]; then
        REL=$(awk < $RELFILE '{print $1}' | awk -F. '{print $1}')    # Checking the distribution name
    elif [ "$arg" = "version" ]; then
        REL=$(awk < $RELFILE '{print $3}' | awk -F. '{print $1}')    # Checking the distribution version
    else
        echo "What do you want?"
        cat $RELFILE
    fi
}
[ "$1" != "name" ] && [ "$1" != "version" ] && echo -e "\n$0 name : to print distribution name\n$0 version : to print distribution version\n" && exit 1
my_release $1
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s