Tell me if this has ever happened to you: you sit down at machine that you are supposed to fix/configure and you realize that you don’t even know what version of OS is it running. That is, you know that it is Windows or Linux or something else. What you don’t know is the OS version, dsistribution and etc.. It might be hard to download and install appropriate packages for a system you know nothing about.
When you are dealing with windows, this is a non-issue. Usually you can spot XP installation from a mile away by the fancy window theme. But even if the machine is running classic you can right click on My Computer and choose properties. Either that or you can type in winver on the command line and look at the pretty information dialog telling you the OS version, service pack and etc.
If you need more info than this, you should probably run msinfo32. It gives you more detailed system information that you will ever really need. Make sure you launch it from the Windows Run dialog rather than from the command line – otherwise it’s not going to work.
But what if you don’t want to or can’t stare at pretty graphical dialogs? What if you are hacking up a batch script, or if you just telneted to some machine on the network and you want to find out more about it? Your first step should probably be issuing the ver command. It’s output is very simple – for example on WinXP machine you will most likely see something like:
Microsoft Windows XP [Version 5.1.2600]
You don’t get any service pack information here, but if you just want to know if this is an XP or non XP machine you are good. If you need more info than this, you can try:
systeminfo | find "OS"
Here is the output I got from a Win 2k3 server:
OS Name: Microsoft(R) Windows(R) Server 2003, Standard Edition
OS Version: 5.2.3790 Service Pack 1 Build 3790
OS Manufacturer: Microsoft Corporation
Unfortunately this command is only present on XP Pro and Win 2k3 machines so it does limit your options a little bit.
But enough about Windows. All in all, there are only 7 or 8 versions of the OS on the market right now that you would likely encounter (from Win Vista RC1 down to Win95 and NT). There are however literally hundreds of “flavors” of Linux and Unix out there. How do you find out which one is sitting on your machine?
Your first step would probably be to run:
uname -a
Uname will tell you whether or not you are actually running linux, unix, BSD or something else. Most unix versions are proprietary, so once you get the vendor name, and version number using this command you should be able to look up more detailed info about your system using vendor specific tools or instructions. Here is a sample output from and old unix machine:
SunOS [name] 5.8 Generic_108528-23 sun4u sparc SUNW,Sun-Fire-880
I removed the machine name just to be on the safe side. ;) If you are running Linux, uname will likely be much less helpful. Here are samples:
Linux inuyasha 2.6.10-6-386 #1 Tue Jul 18 20:18:40 UTC 2006 i686 GNU/Linux
Linux evangelion 2.4.19-64GB-SMP #1 SMP Mon Apr 26 16:31:25 UTC 2004 i686 unknown
I can see that I’m running Linux, and I can see the kernel version but what is my distribution? Most distros will keep more detailed OS version info in /proc/version. For example if I do:
cat /proc/version
on my laptop it will yield the following:
Linux version 2.6.10-6-386 (buildd@terranova) (gcc version 3.3.5 (Debian 1:3.3.5-8ubuntu2.1)) #1 Tue Jul 18 20:18:40 UTC 2006
You can clearly see that the base system is Debian, and that I’m actually running Ubuntu. Now that I know I’m on debian based release, I can do:
lsb_release -a
to obtain nicely formated info on my Debian based system:
LSB Version: n/a
Distributor ID: Ubuntu
Description: Ubuntu (The Hoary Hedgehog Release)
Release: 5.04
Codename: hoary
If you are using a non-debian system you should probably take a peek in /etc/issue. When I do
cat /etc/issue
on my laptop I get the following info back:
Ubuntu 5.04 “Hoary Hedgehog” \n \l
Craig Betts mentioned to me that sometimes the /etc/issue/ file may be used to store security banners or other info, and the OS version may not be present there (see the comments).
Fortunately most distros will also store this information in a specific /etc/*release file. The name of the file is usually distribution specific. For example:
Redhat – /etc/redhat-release
Debian – /etc/lsb-release
SuSE – /etc/SuSE-Release
JDS – /etc/sun-release or /etc/SuSE-release
Solaris – /etc/release
You get the idea. I cannot guarantee that such a file will be present on every unix-like machne, but you should be able to find it on most of them.
Between all these methods you should be able to pin down the exact distribution version of your system. Or at least up to a degree where it doesn’t matter. For example, I can tell you that my laptop is in fact running Kubuntu, not Ubuntu. But does that make a difference? Nope – Kubuntu is simply Hoary packaged with KDE instead of Gnome. Any application and package created for Hoary will run on my system just fine. The worst that can happen is that I will need to download some Gnome specific libraries to get it working.
I’m quite sure that uname will also work on BSD and OSX but the other methods may be Linux exclusive. Feel free to put your BSD and Mac OS version finding tricks in the comments.
[tags]OS, version, windows, linux, redhat, debian, versioning, find os version[/tags]
The machine i’m running on is this (not my own machine, pc lab i’m at)
SunOS titanium.ecs.syr.edu 5.9 Generic_118558-10 sun4u sparc SUNW,Sun-Blade-100
Heh, and you have following ports open: 22, 4045, 32771, 32773 and 32779. That and you are running a NFS file system. :twisted:
Interestingly enough nmap did not detect the OS version.
Carefull when relying on /etc/issue. Many sysadmins use this file for security banners and the OS info will be removed.
Another good spot to look is /etc/*release. I am not too familiar with some of the Linux ditros, but I know RedHat and SuSE work with this (the wildcard will get you the right stuff). This also works for Solaris.
Hey, thanks for the tip Craig! I added it to my post. :)
As Craig said, you can use the /etc/*release files…
Just do a “cat /etc/*release” and you’ll get the info you need :)
However, Fedora systems seem to have both a redhat-release and fedora-release file, which contain the same info, shown here from my Fedora Core 5 box:
root@obiwan:~# cat /etc/*release
Fedora Core release 5 (Bordeaux)
Fedora Core release 5 (Bordeaux)
This is why i did uname on a machine in the unix lab, instead of my own personal pc.
Hahaha! Could not resist port scanning you since you posted the fully qualified domain name here. And this is precisely why I censored the name in one of my uname examples above. I did it on that one Sun machine that we both know all to well ;)
Btw, if you do this on your laptop it will most likely just return the hostname of your machine (in my case it was inuyasha and evangelion). There are local names and they are not associated with any IP address. In fact, inuyasha is a laptop which is on DHCP regularly travels between 3 different networks (school, home, work).
This was so helpful it’s not even funny. I have been looking for a way to find out where these linux distros have been storing their stuff (since it’s not in uname -a)
THANKS SO MUCH!