1

I have been writing a shell script that needs to know if the system one is on is, in fact, Debian-based. Now I have seen this question, but its answers weren't so helpful. I am aware of checking /etc/os-release and the output of lsb_release, likewise I know that checking if rpm or dpkg commands exist is another way of checking whether one's distribution is Red Hat or Debian-based, respectively. All these methods have flaws though. There are hundreds of different Debian-based distros (including those based on Ubuntu, which is in itself based on Debian) and checking whether the NAME field in /etc/os-release, or the Distributor ID in the output of lsb_release -a matches any of the hundreds of known Debian-based distributions would take forever. Checking whether the commands dpkg and rpm exist aren't fool-proof either as some people install other distribution's package managers for various different reasons. For example, on my Ubuntu machine I have RPM installed, partly because sometimes I use the Open Build Service's OSC command, which in some cases requires RPM.

So in short I want a simple and fast way of checking (with certainty) whether the distribution my script finds itself on is Debian-based or not. Is this possible?

EDIT: As people seem to be implying, by voting to close this question, that /etc/debian_version is present on all Debian-based systems. Does anyone have proof of this?

Josh Pinto
  • 3,493

1 Answers1

1

All Debian derivatives should have /etc/debian_version, which is provided by the essential base-files package. Since it's essential you can rely on it being installed, and therefore the file being present.

I say "should" because there's nothing preventing a derivative from deleting that file, but as far as I'm aware none do. See Does Linux Mint have /etc/debian_version? for more details.

Stephen Kitt
  • 434,908