uname command/etc/*-release filespython -mplatform$OSTYPEuname, hostname, machine, sw_vers are all commands you can use.
uname prints operating system name.
LinuxDarwinCentOS

uname has a few flags (a,p,m) you can use.uname : with no arguments will name the operating system.uname -a : check kernel version and system architectureuname -m : will give the “machine hardware name”. Tells whether your system is 32-bit or 64-bit-n : print the nodename (the nodename may be a name that the system is known by to a communications network).uname -p : processor type, but is usually unknown on modern Unix platforms. prints the machine processor architecture name.uname -r : print the operating system release.uname -s : print the operating system name.unae -v : print the operating system version.cat /etc/issue : check CentOS/Ubuntu versioncat /etc/os-release : get distro name 2cat /etc/lsb-release :cat /etc/redhat-release :hostname : check hostname
/bin/arch/ : if it exists, will usually give the type of processor.
echo $OSTYPE : env variable that stores OS name
python -mplatform :
$ cat /etc/issue
Ubuntu 14.04.3 LTS \n \l
Most major distros are moving towards a system where they use /etc/os-release to store this information. Most modern distributions also include the lsb_release tools but these are not always installed by default.
Ubuntu
1cat /etc/os-release
NAME="Ubuntu"
VERSION="14.04.3 LTS, Trusty Tahr"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 14.04.3 LTS"
VERSION_ID="14.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
Doesn’t work on CentOS or OSX it seems.
Ubuntu
1cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.3 LTS"
CentOS
1cat /etc/redhat-release
CentOS release 6.7 (Final)
CentOS actually shows 3 release file names. The other two /etc/redhat-release and /etc/system-release are symlinks to /etc/centos-release.
1ls -alhs /etc/*-release
-rw-r--r-- 1 root root 27 Aug 3 12:12 /etc/centos-release
lrwxrwxrwx 1 root root 14 Aug 7 12:02 /etc/redhat-release -> centos-release
lrwxrwxrwx 1 root root 14 Aug 7 12:02 /etc/system-release -> centos-release
Find and cat the release files. The following commands lists all *-release files in the /etc/ folder.
1ls -alhs /etc/*-release
The bash manpage says that the variable OSTYPE stores the name of the operation system:
OSTYPEAutomatically set to a string that describes the operating system on which bash is executing. The default is system- dependent.
$OSTYPE is darwin15$OSTYPE is linux-gnu1python -mplatform
# Ubuntu
Linux-3.13.0-68-generic-x86_64-with-Ubuntu-14.04-trusty
# CentOS
Linux-2.6.32-042stab108.6-i686-with-centos-6.7-Final
# Mac OS X
Darwin-15.0.0-x86_64-i386-64bit
# Armbian
Linux-3.4.113-sun8i-armv7l-with-Ubuntu-16.04-xenial