Server Fault is a question and answer site for system and network administrators. 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

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?

share|improve this question

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.

share|improve this answer
Couldn't have said it better myself. – womble Oct 5 '09 at 23:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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