I am trying to determine what flavor of linux server is running. I am not trying to determine the kernel version - but rater the distributor.

gcc is installed, and in the version output, it says RedHat

# gcc --version
gcc (GCC) 3.4.6 20060404 (Red Hat 3.4.6-11)

Does this mean I can safely assume my server is a RedHat server. Is there a better - 100% bulletproof method to find this out? Also for other linux flavors - not just this server?

Edit: contents of /etc/ in case it helps - but I would like a solution that works for other versions of linux too.

# ls /etc/
./              backupmxhosts  domainusers     host.conf     localdomains  mailips        pam.d/      relayhosts               shadow              trustedmailhosts
../             bashrc*        exim.conf       inputrc       localtime     man.config     passwd      resolv.conf              skipsmtpcheckhosts  userdomains
DIR_COLORS      cron.deny      exim.pl         ld.so.cache   lynx.cfg      mtab           profile     secondarymx              spammeripblocks     vimrc
aliases         demodomains    exim.pl.local*  ld.so.conf    mail/         my.cnf         profile.d/  senderverifybypasshosts  sudoers
antivirus.exim  demouids       group           localaliases  mailhelo      nsswitch.conf  protocols   services                 termcap

I have no *release or *versionfiles in /etc/

# ls /etc*release; ls /etc/*version
/bin/ls: /etc/*release: No such file or directory
/bin/ls: /etc/*version: No such file or directory

I tried LSB

# lsb_release -a
LSB Version:
Distributor ID: n/a
Description:    (none)
Release:        n/a
Codename:       n/a

Also - I guess I am inside a chroot jail (not really sure what that is) which could likely be the cause for this issue.


I think this does it for me. I think I can safely assume I am using cent-os.

# cat /proc/version
Linux version 2.6.9-103.plus.c4smp (mockbuild@builder10.centos.org) (gcc version 3.4.6 20060404 (Red Hat 3.4.6-11)) #1 SMP Wed Dec 21 16:17:23 EST 2011
  • Why do you need to know? Perhaps instead testing for common distribution-specific tools (package managers, for instance) will do what you want? – Daniel Pryden Oct 7 '11 at 21:21
  • 1
    Well, what I really want to know is if I can replicate the server as a virtual machine locally, and then install stuff on local virtual machine, then copy the binaries over to the remote machine. I thought finding out the correct platform would be a good starting point. – Billy Moon Oct 7 '11 at 21:29
  • 2
    The above directory listing is incomplete (e.g. hosts is missing, init.d, rc*). Is this a test? – ott-- Oct 7 '11 at 21:38
  • How are you accessing this server? Is it possible that you don't have access to the server's filesystem directly, but are instead inside a chroot jail? – Daniel Pryden Oct 7 '11 at 21:52
  • I guess I could be inside a chroot jail - does this mean I can not find out what the underlying system is? – Billy Moon Oct 7 '11 at 22:03

10 Answers 10

cat /proc/version


  1. Ubuntu:

    $ cat /proc/version
    Linux version 3.11.0-13-generic (buildd@roseapple) (gcc version 4.8.1 \
    (Ubuntu/Linaro 4.8.1-10ubuntu8) ) #20-Ubuntu SMP Wed Oct 23 07:38:26 UTC 2013
  2. Red Hat / CentOS:

    $ cat /proc/version
    Linux version 2.6.32-220.13.1.el6.x86_64 (mockbuild@c6b6.bsys.dev.centos.org) \
    (gcc version 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC) ) #1 SMP Tue Apr 17 23:56:34 BST 2012

See also How To Know Which Linux Distribution You Are Using?

  • This shows where was the kernel compiled not what distribution you run on. In many cases the kernel is being compiled on the same distribution but on an older version. – pabouk Nov 20 '13 at 8:48

On most modern Linux distros, the following command will give you its information:

lsb_release -a
  • 1
    No, this is not true. This works only for Debian and derivatives – MariusMatutiae Nov 20 '13 at 7:48
  • 1
    This command is not installed by default on Red Hat and derivatives (i.e. CentOS). You have to install it explicitly before use: yum install redhat-lsb-core. – pabouk Nov 20 '13 at 9:03
  • @MariusMatutiae actually it is much more widespread than that but is not always installed by default. – terdon Dec 19 '13 at 17:06
  • @terdon thank you, I did not know that. – MariusMatutiae Dec 19 '13 at 17:09
  • @MariusMatutiae see here for more info, it seems to be absent from SuSe but should be installed on RH. – terdon Dec 19 '13 at 17:11

/etc/issue might be a good starting point.

More could be found by inspecting the info files for different distributions:

Novell SuSE    /etc/SuSE-release
OpenSuSE       /etc/SuSE-release, /etc/os-release
Red Hat,CentOS /etc/redhat-release, /etc/redhat_version
Fedora         /etc/fedora-release, /etc/redhat-release, /etc/os-release
Slackware      /etc/slackware-release, /etc/slackware-version
Debian         /etc/debian_release, /etc/debian_version
Mandrake       /etc/mandrake-release
Yellow dog     /etc/yellowdog-release
Sun JDS        /etc/sun-release 
Solaris/Sparc  /etc/release 
Gentoo         /etc/gentoo-release
Amazon Linux   /etc/system-release
PLD Linux      /etc/pld-release, /etc/os-release
ArchLinux      /etc/arch-release, /etc/os-release

See Unix forum for more details.

  • 1
    unfortunately I don't have any files ending release or version in my etc directory – Billy Moon Oct 7 '11 at 21:32

If /etc/issue is missing, there may be one or more /etc/*_release files.

For example, my Ubuntu system has /etc/lsb-release:


A friend's CentOS system (based on Red Hat) has /etc/redhat-release:

CentOS release 5.6 (Final)

I don't know how universal this is.

  • no release or version files in my /etc/ – Billy Moon Oct 7 '11 at 21:34
  • @BillyMoon I believe it is only recent that Linux distributions started to add the lsb_release utility on their distribution. lsb_release -a – Alpha01 Oct 7 '11 at 21:42
  • Thanks for the tip - does not help me this time unfortunately – Billy Moon Oct 7 '11 at 22:01

cat /etc/issue might answer your question.

The distro makers are not friendly to you here. First, each one thinks it is the only one true way.

Most likely, instead of trying to sniff the distro, you should be looking in more detail at the particular question you actually need to answer. Focus on the functionality you are looking at, not the distro providing it. After all, a new version of a distro can turn around and go in the opposite direction on any particular axis.

  • 3
    there is no /etc/issue on my server – Billy Moon Oct 7 '11 at 21:17
  • Yes. Note that /etc/issue may contain escape sequences such as \n and \l. To see what these mean, man 5 issue and man getty (the /etc/issue file is primarily intended for use by getty). Of course the owner of the system could edit /etc/issue for some nefarious reason. – Keith Thompson Oct 7 '11 at 21:18
  • I don't think /etc/issue is required to exist, or to contain any information about the distribution vendor. It commonly does, but I don't think you can rely on it. – Daniel Pryden Oct 7 '11 at 21:20
  • @DanielPryden well one learns something every day. I'd never run into the absence of one myself before. – bmargulies Oct 9 '11 at 23:50

Use facter (yes that is how it is spelled).

Facter is a companion to puppet, it provides variables that can be queried which contain information about the system.

For example, here are just a few of the dozens of variables that factor can return

$ facter
operatingsystem => CentOS
operatingsystemmajrelease => 6
operatingsystemrelease => 6.4
osfamily => RedHat

You could simply query the osfamily fact to see that the server is running RedHat

$ facter osfamily

Check out the documentation: http://puppetlabs.com/facter


uname -a

Works always for any Tux

  • 1
    That reports the kernel version string, which could be very wrong if your host is running a kernel from a different distribution -- either on bare metal or because of a tool like OpenVZ or VServers. – sarnold Oct 9 '11 at 1:10
  • Yes, but I suppose in this case author of Q will know smth. about situation. "Foreign" kernel is rather odd case – Lazy Badger Oct 9 '11 at 1:42

There is no single sure fire way of doing this. I asked a similar question over on unix.se and the best way of getting this info is a script that checks a variety of sources:

# Detects which OS and if it is Linux then it will detect which Linux
# Distribution.

OS=`uname -s`
REV=`uname -r`
MACH=`uname -m`

    VERSION=`cat $1 | tr "\n" ' ' | sed s/.*VERSION.*=\ // `

if [ "${OS}" = "SunOS" ] ; then
    ARCH=`uname -p` 
    OSSTR="${OS} ${REV}(${ARCH} `uname -v`)"
elif [ "${OS}" = "AIX" ] ; then
    OSSTR="${OS} `oslevel` (`oslevel -r`)"
elif [ "${OS}" = "Linux" ] ; then
    KERNEL=`uname -r`
    if [ -f /etc/redhat-release ] ; then
        PSUEDONAME=`cat /etc/redhat-release | sed s/.*\(// | sed s/\)//`
        REV=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//`
    elif [ -f /etc/SuSE-release ] ; then
        DIST=`cat /etc/SuSE-release | tr "\n" ' '| sed s/VERSION.*//`
        REV=`cat /etc/SuSE-release | tr "\n" ' ' | sed s/.*=\ //`
    elif [ -f /etc/mandrake-release ] ; then
        PSUEDONAME=`cat /etc/mandrake-release | sed s/.*\(// | sed s/\)//`
        REV=`cat /etc/mandrake-release | sed s/.*release\ // | sed s/\ .*//`
    elif [ -f /etc/debian_version ] ; then
        DIST="Debian `cat /etc/debian_version`"

    if [ -f /etc/UnitedLinux-release ] ; then
        DIST="${DIST}[`cat /etc/UnitedLinux-release | tr "\n" ' ' | sed s/VERSION.*//`]"



echo ${OSSTR}

The other choice is indeed using gcc --version, since gcc is always compiled for a particular distro, this will be relatively portable. I highly recommend you read the accepted answer on my question at U&L it explains the situation very nicely.


This command worked for Debian based and Redhat based distributions: Using tr filter, you convert the document to one-word-per-line format and then count the first line which contains the distribution name.

tr -s ' \011' '\012' < /etc/issue | head -n 1

Thos is the best method

cat /etc/*release
  • I listed my /etc directory in the question. As discussed on other answers, this solution does not work for me. – Billy Moon Nov 20 '13 at 9:10
  • U tried ls /etc*release; . It is wrong. Try ls /etc/*release. It will work .am pretty sure – Unnikrishnan Nov 20 '13 at 9:41
  • I also did ls in /etc/ directory and you can see that no files in there end in release – Billy Moon Nov 20 '13 at 12:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.