0

What I want is a quick, reliable command to ascertain that the Linux I'm running in is Debian-based. The following command seems to work. It also returns the Debian version:

dpkg -L base-files 2>/dev/null | grep '^/etc/debian_version$' >/dev/null 2>&1 && cat /etc/debian_version

My previous idea was to use dpkg -S /etc/debian_version to see if it belonged to some package, regardless of name. But dpkg -S is slow.

I only have a lingering doubt: are there older Debian-derivated distros where my assumption doesn't hold? Is there a better way?

JCCyC
  • 670
  • 2
  • 13
  • 24

2 Answers2

4

A better approach is to test that what you want to do is possible rather than relying on what the distribution is. For example my Ubuntu box claims it is "squeeze/sid". If you want to install something via dpkg, check dpkg is where you expect it an is executable. If you want to modify the networking setup? Check that /etc/networking/interfaces exists. Check for tools like update-rc.d etc.

You should also use /etc/lsb-release rather than /etc/debian_version.

David Pashley
  • 23,151
  • 2
  • 41
  • 71
1

I don't believe you can make that assumption no.

Please see:

Zoredache
  • 128,755
  • 40
  • 271
  • 413