Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

I need to collect some system info from machines and decide what to do based on some distribution/version -specific conditionals.

To simplify my example, I concocted a fictitious my_function_display_operating_system function. It is a useless function but it frames the problem:

  1. detect the general OS type (, , etc.)
  2. detect some version information about the OS
  3. detect the distribution friendly name

Point 3. is what I most need help with, please.

Is there a reliable way to read a string indicating the host distribution name?

I am using /etc/issue in the example below as I know of no other way, or set of ways, to get to this information.

I am happy with a it depends answer, I can build a quite involved case esac switch statement if need be.

I just need to know where to look, and I can't download/install VMs for all the distros I know of to "look around" and/or for the name..

# Displays operating system.

function my_function_display_operating_system() {
  local operating_system
  case $my_global_os_type in
      printf -v operating_system \
                'OS X v%s (build %s)' \
                $(sw_vers -productVersion) \
                $(sw_vers -buildVersion)
      local -r linux_kernel_version=$(uname -r)
      printf -v operating_system \
                'GNU/Linux (kernel %s)' \
      if [[ -f /etc/issue ]]; then
        local -r distribution=$(cat /etc/issue | sed 's/ \\n \\l//g')
        operating_system+="\nDistribution: $distribution"
  printf "Operating system: $operating_system\n"

Sample output:

> my_function_display_system_information
Operating system   GNU/Linux (kernel 3.5.0-25-generic)
Distribution       Ubuntu 12.10
System memory      1 GB
Bash               v4.2.37(1)-release
Vim                VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Oct 26 2012 16  45  54)
# ... etc ...

share|improve this question

marked as duplicate by Renan, jasonwryan, jordanm, uther, derobert Apr 2 '13 at 22:44

This question was marked as an exact duplicate of an existing question.

Yes! It's a dup! – Robottinosino Apr 2 '13 at 22:35

Very similar advice given here:


The short answer:

 ls /etc/*{release,version}

Various distributions will spit out different formats, unfortunately there's no single uniform system. The answer above lists much more specifically some of the most common files to look for.

share|improve this answer

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