/etc/*release files examples
Solution 1
Not all systems have /etc/*release*
files, so if you really want this to be cross-Unix you can't use them.
The POSIX-blessed solution is uname
-- If all you need is a coarse OS ID uname -s
will probably suffice.
I'm not aware of any canonical list of uname output, but Wikipedia has a table that may be a good starting point (and presumably you have access to the platforms you're trying to detect so you can check what they return).
Sometimes uname
doesn't tell the whole story (e.g. Linux distributions, which have substantial variability) - If it's necessary you can figure out more specific information (like "Which Linux distribution?") with a second pass that uses a system-specific tool (like lsb_release
on Linux, or oslevel
on AIX)
Solution 2
Most distributions have a tool called lsb_release
.
Gentoo:
$ lsb_release -a
LSB Version: n/a
Distributor ID: Gentoo
Description: Gentoo Base System release 2.0.3
Release: 2.0.3
Codename: n/a
CentOS:
$ lsb_release -a
LSB Version: :core-4.0-ia32:core-4.0-noarch:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-ia32:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 5.7 (Final)
Release: 5.7
Codename: Final
Other *nix distros: http://linuxmafia.com/faq/Admin/release-files.html
Related videos on Youtube
Vic
Updated on September 18, 2022Comments
-
Vic over 1 year
Where can I find a list of different
/etc/*release
files of various Linux/Unix/MacOS distributions and versions?Same goes to
uname -a
command outputs.-
JMeterX over 11 yearsIf you don't mind me asking, why?
-
Vic over 11 years@JMeterX there's a subset of platforms and versions I need to identify programmatically after connecting to a remote machine.
-
Zoredache over 11 yearsrelated: serverfault.com/questions/119144/…
-
Zoredache over 11 yearsInstall facter? Use its output?
-
-
voretaq7 over 11 yearsThe only problem with
lsb
tools is they don't work on OS X, AIX, Solaris, any BSD system, HP-UX... -
Greg Petersen over 11 years
-
voretaq7 over 11 yearsIf you wind up using
uname
as part of your detection process it would be a kindness for the next poor soul who has to do this if you could update that Wikipedia article with theuname
output from from operating systems which aren't listed :-) -
Bob over 2 yearsWelcome to Server Fault! Please use cut-and-paste for posting console output and format it as "
code
" using Markdown and/or the formatting options in the edit menu to properly type-set your post rather than posting screenshots. That improves readability, attracts better answers and allows indexing by search engines, which may help people with similar questions. -
Vitalie Ghelbert over 2 yearsQuestion is index of searching. I am just the shadow of the Question. @Bob