Detecting Underlying Linux Distro
If you are the owner of the system, then you know which Linux is installed and running. This article will help you to understand how to determine which Linux distribution is installed. You can incorporate this into your application to detect Linux distro.
System Command: uname
Most of the Linux systems provide uname to detect system released information.
Release Information File
Most of the Linux distributions maintain release information file in an/etc/directory. Here is the list of files on some of the well known Linux distributions:
Novell SUSE | /etc/SUSE-release |
Red Hat | /etc/redhat-release, /etc/redhat_version |
Fedora | /etc/fedora-release |
Slackware | /etc/slackware-release, /etc/slackware-version |
Debian | /etc/debian_release, /etc/debian_version, |
Mandrake | /etc/mandrake-release |
Yellow dog | /etc/yellowdog-release |
Sun JDS | /etc/sun-release |
Solaris/Sparc | /etc/release |
Gentoo | /etc/gentoo-release |
UnitedLinux | /etc/UnitedLinux-release |
ubuntu | /etc/lsb-release |
Sample Script
Using system command uname and contents of the release files you can write scripts of programs to help your software to detect distribution.
#!/bin/sh
# Detects which OS and if it is Linux then it will detect which Linux Distribution. OS=`uname -s`
REV=`uname -r`
MACH=`uname -m` GetVersionFromFile()
{
VERSION=`cat $1 | tr "\n" ' ' | sed s/.*VERSION.*=\ // `
} if [ "${OS}" = "SunOS" ] ; then
OS=Solaris
ARCH=`uname -p`
OSSTR="${OS} ${REV}(${ARCH} `uname -v`)"
elif [ "${OS}" = "AIX" ] ; then
OSSTR="${OS} `oslevel` (`oslevel -r`)"
elif [ "${OS}" = "Linux" ] ; then
KERNEL=`uname -r`
if [ -f /etc/redhat-release ] ; then
DIST='RedHat'
PSUEDONAME=`cat /etc/redhat-release | sed s/.*\(// | sed s/\)//`
REV=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//`
elif [ -f /etc/SUSE-release ] ; then
DIST=`cat /etc/SUSE-release | tr "\n" ' '| sed s/VERSION.*//`
REV=`cat /etc/SUSE-release | tr "\n" ' ' | sed s/.*=\ //`
elif [ -f /etc/mandrake-release ] ; then
DIST='Mandrake'
PSUEDONAME=`cat /etc/mandrake-release | sed s/.*\(// | sed s/\)//`
REV=`cat /etc/mandrake-release | sed s/.*release\ // | sed s/\ .*//`
elif [ -f /etc/debian_version ] ; then
DIST="Debian `cat /etc/debian_version`"
REV="" fi
if [ -f /etc/UnitedLinux-release ] ; then
DIST="${DIST}[`cat /etc/UnitedLinux-release | tr "\n" ' ' | sed s/VERSION.*//`]"
fi OSSTR="${OS} ${DIST} ${REV}(${PSUEDONAME} ${KERNEL} ${MACH})" fi echo ${OSSTR}
from http://www.novell.com/coolsolutions/feature/11251.html
Detecting Underlying Linux Distro的更多相关文章
- 详解Linux交互式shell脚本中创建对话框实例教程_linux服务器
本教程我们通过实现来讲讲Linux交互式shell脚本中创建各种各样对话框,对话框在Linux中可以友好的提示操作者,感兴趣的朋友可以参考学习一下. 当你在终端环境下安装新的软件时,你可以经常看到信息 ...
- 构建 ARM Linux 4.7.3 嵌入式开发环境 —— BusyBox 构建 RootFS
上一篇我们已经成功将 ARM Linux 4.7.3 的内核利用 U-BOOT 引导了起来.但是细心的你会发现,引导到后面,系统无法启动,出现内核恐慌 (Kernel Panic). 原因是找不到文件 ...
- Howto: Connect MySQL server using C program API under Linux or UNIX
From my mailbag: How do I write a C program to connect MySQL database server? MySQL database does su ...
- Linux: 20 Iptables Examples For New SysAdmins
Linux comes with a host based firewall called Netfilter. According to the official project site: net ...
- How to install Node.js on Linux
How to install Node.js on Linux Posted on November 13, 2015 by Dan Nanni Leave a comment Question: H ...
- Linux - 升级+编译kernel
For upgrading present kernel to linux-next kernel, we need to follow below steps. 1. Check present k ...
- How to install JDK (Java Development Kit) on Linux
This tutorial will guide you on how to install JDK (Java Development Kit) on Linux. Since I use Cent ...
- 通过SSHFS在RHEL中安全的挂载远程Linux/UNIX目录或文件系统--转载
You can easily mount remote server file system or your own home directory using special sshfs and fu ...
- How to run OFBiz as a Service on linux
Windows See this specific guide: How to Run OFBiz as Windows Service with Java Service Wrapper Linux ...
随机推荐
- cross apply 和 outer apply
使用APPLY运算符可以实现查询操作的外部表表达式返回的每个调用表值函数.表值函数作为右输入,外部表表达式作为左输入. 通过对右输入求值来获得左输入每一行的计算结果,生成的行被组合起来作为最终输出.A ...
- N皇后问题的实现
N皇后问题是一个经典的问题,是回溯算法的典型案例.它是由国际西洋棋棋手马克斯·贝瑟尔于1848年提出的八皇后问题延伸而来的,具体要求如下:在N*N的方格棋盘放置N个皇后,使她们彼此不相互攻击,即任意2 ...
- Ansible playbook基础组件介绍
本节内容: ansible playbook介绍 ansible playbook基础组件 playbook中使用变量 一.ansible playbook介绍 playbook是由一个或多个“pla ...
- hdu 3537 翻硬币 每次能翻1个 或2个 或3个
N 枚硬币排成一排,有的正面朝上,有的反面朝上.我们从左开始对硬币按1 到N 编号. 第一,游戏者根据某些约束翻硬币,但他所翻动的硬币中,最右边那个硬币的必须是从正面翻到反面. 第二,谁不能翻谁输. ...
- jboss各种测试方式归类
不跨工程访问(如:HBase) 跨工程访问(如:Business) 不部署到服务器上 部署到服务器上 不部署到服务器上 部署到服务器上 Junit测试 实例化直接调用 true true Fals ...
- CCF CSP 201709-1 打酱油
CCF计算机职业资格认证考试题解系列文章为meelo原创,请务必以链接形式注明本文地址 CCF CSP 201709-1 打酱油 问题描述 小明带着N元钱去买酱油.酱油10块钱一瓶,商家进行促销,每买 ...
- Linux 中 &、jobs、fg、bg 等命令
参考 Unix 或 Linux 中 &.jobs.fg.bg 等命令的使用方法 对之前文章的一个补充: linux 命令后台运行 这篇还是比较简单的,稍微一带而过 fg.bg.jobs.&a ...
- #define const typedef
#define用法 1. 定义简单的常数:定义常量,便于修改 #define N 1000 2. 定义简单的函数:注意多使用括号 define可以像函数那样接受一些参数,如下: #define max ...
- 【LOJ】#2384. 「HNOI2013」切糕
题解 神仙网络流啊-- naive的我一直想把每个纵轴拆点,每个纵轴建R个点(大概是要跑费用流吧--)--然后第二个限制就gg了,什么也想不出来,菜啊TAT 后来我发现大神们的建图都是,一个原点,一个 ...
- 【转】JQuery Validate使用总结二
Jquery Validate使用总结一 五.常用方法及注意问题 1.用其他方式替代默认的SUBMIT $().ready(function() { $("#signupForm" ...