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 ...
随机推荐
- Python基础 - 正则表达式
Python自带正则表达式模块,即re模块. 导入正则模块: import re 用dir()函数查看re模块内的属性和方法: dir(re)
- java 局部内部类
可以在代码块里创建内部类,典型的方法是在一个方法体的里面创建,局部内部类不能有访问说明符,因为它不是外围类的一部分,但是可以访问当前代码块的常量,以及此外围类的所有成员,下面分别对局部内部类和匿名内部 ...
- Centos中查询目录中内容命名ls
首先解释下这块, root代表当前登录用户,localhost代表主机名, ~代表当前主机目录, #代表用户权限 #表示超级用户,$表示普通用户: 查询目录中内容命令 ls (list缩写) ...
- SQL Server数据库存在判断语句及系统表简介
Transact-SQL Exists Sentences--判断数据库是否存在IF EXISTS(SELECT * FROM master.sysdatabases WHERE name=N'库名' ...
- 34、疯狂java讲义第三版
内容中包含 base64string 图片造成字符过多,拒绝显示
- pytest的参数化测试
感觉在单元测试当中可能有用, 但在django这种框架中,用途另一说. import pytest import tasks from tasks import Task def test_add_1 ...
- Linux 中 &、jobs、fg、bg 等命令
参考 Unix 或 Linux 中 &.jobs.fg.bg 等命令的使用方法 对之前文章的一个补充: linux 命令后台运行 这篇还是比较简单的,稍微一带而过 fg.bg.jobs.&a ...
- 使用Let’s Encrypt创建nginx免费SSL证书
资料参考: https://www.freehao123.com/top-8-free-ssl-cert/ 八大免费SSL证书-给你的网站免费添加Https安全加密 https://www.fre ...
- python实现获取系统版本和mac信息上传到指定接口
import os,platform,uuid,urllib.parse,urllib.request,json def BeforeSystemRequests(): ''' the systemi ...
- (转)最短路算法--Dijkstra算法
转自:http://blog.51cto.com/ahalei/1387799 上周我们介绍了神奇的只有五行的Floyd最短路算法,它可以方便的求得任意两点的最短路径,这称为“多源最短 ...