I'm starting to work with a box that has a custom (small) Linux build on it. How can I tell whether this is a Debian or Red Hat-based build?

This is what I know so far:

$ cat /proc/version
Linux version 2.6.31-2.5 (build@build-desktop) (gcc version 4.4.3 (Broadcom stbgcc-4.4.3-1.2) ) #7

$ apt-get
-sh: apt-get: command not found

$ yum
-sh: yum: command not found
  • why lsb_release -i 2> /dev/null | sed 's/:\t/:/' | cut -d ':' -f 2- ?? Just run lsb_release -si
    – user196425
    Oct 22, 2016 at 4:24

5 Answers 5


For testing for Debian systems, you can check whether /etc/debian_version exists:

if [ -f "/etc/debian_version" ]; then
   # do stuff

It should be included in Debian and systems based on it (including Ubuntu and its derivatives), though a few may not have it — in this case, you can check all /etc/*release files:

if [ "$(grep -Ei 'debian|buntu|mint' /etc/*release)" ]; then
   # do stuff

Where debian|buntu|mint is a list of distribution names to look for (not case sensitively) — you can get an idea of some common derivatives from here, though Debian derivatives like Ubuntu have their own derivatives.

For RedHat based systems, the derivatives use a larger range of files, and might not have lsb-release installed — so you can apply the following methods:

  • get the release name from

     lsb_release -i 2> /dev/null | sed 's/:\t/:/' | cut -d ':' -f 2-
  • check the DISTRIB-ID in the lsb-release file — a fallback method that is probably unnecessary on modern systems, also, the file apparently is missing on Fedora, and does not contain DISTRIB_ID on OpenSUSE

  • check for the existence of some of the following

    • /etc/fedora-release and/or /etc/redhat-release for Fedora or RedHat, respectively
    • /etc/SuSE-release for SuSe
    • /etc/mandriva-release for mandriva/mageia
  • use a similar method to the latter Debian one:

     if [ "$(grep -Ei 'fedora|redhat' /etc/*release)" ]; then

The first 3 points I sourced from the update cron of Google Chrome, so you could examine that to find out more (it also determines package managers).

For a wider range of OSs, "How to detect the OS from a Bash script?" [on Stack Overflow] should help.


Running uname -a should give you some general information about the system. Also, you can run apropos "package manager" or with similar keywords to hopefully find out more about the package manager. Look in /etc for a file named xyz-release where xyz should be whatever distro is running.

  • This is what I get when I run uname -a: $ uname -a Linux 2.6.31-2.5 #7 Thu Dec 15 19:57:09 CST 2011 mips GNU/Linux
    – Sparky1
    Jan 25, 2012 at 17:40
  • @Sparky1 Then, it seems you have gotten yourself a Linux-MIPS distribution.
    – user13742
    Jan 25, 2012 at 19:05

Check output of:

lsb_release -a


cat /etc/issue

You can also check for more low-lever package commands rpm for RedHat and dpkg for Debian.

  • $ dpkg command not found $ rpm (shows options for the rpm command). Looks like this a red hat based build. Thanks for the help!
    – Sparky1
    Jan 25, 2012 at 17:43
  • 2
    you can also check /etc/debian_version file, which exists in all debian based linux distribution
    – Coren
    Jan 25, 2012 at 20:30
  • Also install it using apt-get install lsb-release if it's not installed. Aug 18, 2016 at 8:23

If it's an embedded device (e.g. a SoHo router), it probably won't be any of the "desktop/server" distros. I'd try to look into the device's manual, manufacturer's website (should have source to the GPL-licensed code), and the Web at large.


uname -a and cat /proc/version (read-only for superusers), in my honest opinion, are the only correct answers to this question as the rest - like lsb_release, /etc/issue or cat /proc/sys/kernel/version - are not available/not usable on every system (not even official Debian distros). Also don't bother using /etc/*releases, /etc/*version since they can be altered. The latter is not available on all Debian distros.

Other options could be (not my recommendation):

  • Check for dash or verify if sh is linked to dash (it should be the default for running scripts)
  • Check the package manager by executing >/dev/null 2>&1 dpkg --version && { ... }
  • uname -a and cat /proc/version provide information on the executing kernel. So e.g. within a container (e.g. Docker, lxc, etc.), these commands show information about the container's host distribution. The host may be different from the container (e.g. host is Debian, container is Arch).
    – Abdull
    Sep 11, 2023 at 11:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .