ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Linux: Finding What Distro We Are Using

    IT Discussion
    linux centos rhel ubuntu suse fedora sam linux administration
    6
    11
    2.6k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • scottalanmillerS
      scottalanmiller
      last edited by

      A very common task of both system administrators and of automation scripts is to attempt to determine exactly what operating system (or distribution / distro in Linux parlance) and version number we are running. There is no standard terminology for this as there is no common system component that defines what is the OS, what version it is and so forth. So distro maintainers have turned to a relatively simplistic text file methodology that handles this for us. Simple, but effective. Nearly every Linux-based distro, and certainly all enterprise server ones, use the same standard pattern for storing the operating system name and version information to make it as easy as is reasonable for us to identify what kind of system we are running on. This is especially important to know this as it will often be the first place that we look when logging into a new machine for the first time.

      Sadly, things are just a tiny bit different for each major distro. But knowing the basics should always make it very easy to find.


      CentOS, RHEL and Fedora

      cat /etc/redhat-release
      

      Suse

      cat /etc/SuSE-release
      

      Debian

      cat /etc/debian_version
      

      Arch Linux

      cat /etc/arch-release
      

      Gentoo

      cat /etc/gentoo-release
      

      Slackware

      cat /etc/slackware-version
      

      There are some attempts at making some standard tools so that you can query the same thing on many different distros. These are not catching on universally, however. But some that you can always try are...

      cat /etc/os-release
      cat /etc/lsb-release
      

      Part of a series on Linux Systems Administration by Scott Alan Miller

      1 Reply Last reply Reply Quote 3
      • DashrenderD
        Dashrender
        last edited by

        I'm confused - wouldn't you have to know what distro you're using to run those commands.

        i.e. you can't run the

         cat /etc/gentoo-release
        

        command on Ubuntu, can you? and if you can, can you run it on another Linux family line?

        JaredBuschJ scottalanmillerS momurdaM 3 Replies Last reply Reply Quote 0
        • JaredBuschJ
          JaredBusch @Dashrender
          last edited by

          @Dashrender said in Linux: Finding What Distro We Are Using:

          I'm confused - wouldn't you have to know what distro you're using to run those commands.

          i.e. you can't run the

           cat /etc/gentoo-release
          

          command on Ubuntu, can you? and if you can, can you run it on another Linux family line?

          Of course you can. You simply get an error that there is no file.

          the command is cat the parameter is the path and file name.

          1 Reply Last reply Reply Quote 1
          • JaredBuschJ
            JaredBusch
            last edited by

            root@jaredweb:[~] $ cat /etc/gentoo-release
            cat: /etc/gentoo-release: No such file or directory
            root@jaredweb:[~] $ cat /etc/redhat-release
            CentOS Linux release 7.3.1611 (Core)
            root@jaredweb:[~] $
            
            
            1 Reply Last reply Reply Quote 1
            • scottalanmillerS
              scottalanmiller @Dashrender
              last edited by

              @Dashrender said in Linux: Finding What Distro We Are Using:

              I'm confused - wouldn't you have to know what distro you're using to run those commands.

              i.e. you can't run the

               cat /etc/gentoo-release
              

              command on Ubuntu, can you? and if you can, can you run it on another Linux family line?

              You have to know what to look for and look for it. Same with anything. How do you know that you are on Windows? You rely on look and feel, knowing ahead of time what it is. If you make a Linux desktop look just like Windows and answer to Windows commands, how would you determine that it is really Windows?

              It's harder than it sounds.

              You also have to know that it is Linux, what if it was AIX or HP-UX? At some point you just have to know what things look like and poke around.

              A simple solution for Linux machines is to do this...

              ls /etc/ | grep release

              1 Reply Last reply Reply Quote 0
              • scottalanmillerS
                scottalanmiller
                last edited by

                You can do this as well:

                cat /etc/*release
                

                And see the output of every file with the name all at once. But you might get more than you wanted.

                JaredBuschJ 1 Reply Last reply Reply Quote 1
                • thwrT
                  thwr
                  last edited by

                  Most distros will also give you a hint when opening a session (SSH, bash, getty etc). But it's nice to see such a summary, thanks.

                  1 Reply Last reply Reply Quote 2
                  • JaredBuschJ
                    JaredBusch @scottalanmiller
                    last edited by

                    @scottalanmiller said in Linux: Finding What Distro We Are Using:

                    You can do this as well:

                    cat /etc/*release
                    

                    And see the output of every file with the name all at once. But you might get more than you wanted.

                    For exampels, CentOS 7 has 4 files that match.

                    root@jaredweb:[~] $ ls /etc/*release
                    /etc/centos-release  /etc/os-release  /etc/redhat-release  /etc/system-release
                    

                    It would output this disaster

                    root@jaredweb:[~] $ cat /etc/*release
                    CentOS Linux release 7.3.1611 (Core)
                    NAME="CentOS Linux"
                    VERSION="7 (Core)"
                    ID="centos"
                    ID_LIKE="rhel fedora"
                    VERSION_ID="7"
                    PRETTY_NAME="CentOS Linux 7 (Core)"
                    ANSI_COLOR="0;31"
                    CPE_NAME="cpe:/o:centos:centos:7"
                    HOME_URL="https://www.centos.org/"
                    BUG_REPORT_URL="https://bugs.centos.org/"
                    
                    CENTOS_MANTISBT_PROJECT="CentOS-7"
                    CENTOS_MANTISBT_PROJECT_VERSION="7"
                    REDHAT_SUPPORT_PRODUCT="centos"
                    REDHAT_SUPPORT_PRODUCT_VERSION="7"
                    
                    CentOS Linux release 7.3.1611 (Core)
                    CentOS Linux release 7.3.1611 (Core)
                    
                    1 Reply Last reply Reply Quote 1
                    • JaredBuschJ
                      JaredBusch
                      last edited by JaredBusch

                      What can be done if you do not want to rely on a maybe like

                      cat /etc/os-release
                      cat /etc/lsb-release
                      

                      Is to write your own if/then script to find the data you need.

                      1 Reply Last reply Reply Quote 1
                      • momurdaM
                        momurda @Dashrender
                        last edited by

                        @Dashrender Yes that is generally true. However you usually are only going to have 2 options, redhat_release or debian as those are by far the two most common in use in any business environment.
                        also the os-release seems to be very new for distros. It is not in my centOS 6.6 or 6.8 but is in my debian 8+, but not in a debian 5 server i have.
                        typing
                        cat /etc/os then tab complete will get you possibilities with os in etc dir. If os-release isnt there it isnt.
                        so you can cat /etc/r then tab complete to see redhat-release

                        1 Reply Last reply Reply Quote 0
                        • stacksofplatesS
                          stacksofplates
                          last edited by stacksofplates

                          /proc/version usually has pertinent information across most systems.

                          Edit: I looked closer. It's just the OS name (RHEL/Ubuntu) and kernel version. Never mind.

                          1 Reply Last reply Reply Quote 0
                          • scottalanmillerS scottalanmiller referenced this topic on
                          • 1 / 1
                          • First post
                            Last post