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?


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.

  • Couldn't have said it better myself. – womble Oct 5 '09 at 23:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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