zkwhqq
Last Updated: February 25, 2016
·
250
· victorbrca
409302 10151131950910230 214813917 n 2

Find Linux distro

Use the code below to find out what distro you are:

SYSTEM=$(uname -a | awk '{print $1}')
if [ $SYSTEM = "Linux" ] ; then
  if [ "$(which lsb_release)" ] ; then
    DISTRO=$(lsb_release -si)
  elif [ -f /etc/issue.net ] ; then
    DISTRO=$(head -1 /etc/issue.net | sed 's/\([a-zA-Z]*\)\([0-9].*\)/\1/g' | sed 's/release//')
    DISTRO=${DISTRO// /}
  else
    echo "Could not find Linux distro"
  fi
fi

Use your "if" or "case" conditions to match the following strings

# Ubuntu
# LinuxMint
# Debian
# OpenSuse
# RedHat*
# CentOS
# archlinux
# CrunchBang*
# EnterpriseEnterpriseServer|OracleLinuxServer

Examples

if [ "$DISTRO" =~ "(Ubuntu|LinuxMint)" ] ; then
  # Ubuntu or Linux Mint code here
elif [ "$DISTRO" = "OpenSuse" ] ; then
  # OpenSuse code here
elif [[ "$DISTRO" =~ "RedHat*" ]] ; then
  # RedHat code here
elif [ "$DISTRO" = "CentOS" ] ; then
  # CentOS code here
fi

See Linux Distro Info DB for additional data that you can use to find the distro.

Other links:

http://www.binarytides.com/linux-command-to-check-distro/
http://community.linuxmint.com/iso/reports/237/44

Say Thanks
Respond
Filed Under