找出debian发布名称的可靠方法

时间:2015-03-17 07:55:34

标签: shell ubuntu debian

我有一个脚本需要知道debian系统的发布名称是什么(例如:trusty,sid,wheezy等)。我知道我可以通过查找/etc/debian_version来了解我是否使用基于Debian的系统,但是:

cat /etc/debian_version

cat /etc/issue

Debian Stable上的

产生:

root@07156660e2cd:/# cat /etc/debian_version 7.8 root@07156660e2cd:/# cat /etc/issue
Debian GNU/Linux 7 \n \l

在Ubuntu上产生:

```root @ a81e3f32b147:/ #cat / etc / issue Ubuntu 14.04.2 LTS \ n \ l

root @ a81e3f32b147:/ #cat / etc / debian_version 杰西/ SID ```

我如何获得Ubuntu的代号(在这种情况下是'Trusty')?我不想在名称上维护发布版本的词典。系统中有没有办法找到这些信息?

谢谢!

3 个答案:

答案 0 :(得分:0)

使用lsb_release

lsb_release -c

答案 1 :(得分:0)

@svlasov回答有点太多了

lsb_release -sc只返回代码名称

例如

$ lsb_release -sc
utopic

答案 2 :(得分:0)

在码头图片中,我不能使用uname或其他东西。所以我正在使用:

DEBIAN_RELEASE=$(awk -F'[" ]' '/VERSION=/{print $3}'  /etc/os-release | tr -cd '[[:alnum:]]._-' )

或不依赖于/ etc / os-release

awk -F'[" ]' '/VERSION=/{print $3}'  /etc/*-release | head -1 |tr -cd '[[:alnum:]]._-'

PS:

对于我正在使用的基于Debian的docker镜像:

RUN export  DEBIAN_FRONTEND=noninteractive && \
     export DEBIAN_RELEASE=$(awk -F'[" ]' '/VERSION=/{print $3}'  /etc/os-release | tr -cd '[[:alnum:]]._-' ) &&
     echo "remove main from /etc/apt/sources.list" && \
     sed -i '/main/d' /etc/apt/sources.list && \
     echo "remove contrib from /etc/apt/sources.list" && \
     sed -i '/contrib/d' /etc/apt/sources.list && \
     echo "remove non-free from /etc/apt/sources.list" && \
     sed -i '/non-free/d' /etc/apt/sources.list && \
     echo "deb http://httpredir.debian.org/debian ${DEBIAN_RELEASE} main contrib non-free"  >> /etc/apt/sources.list && \
     echo "deb http://httpredir.debian.org/debian ${DEBIAN_RELEASE}-updates main contrib non-free"  >> /etc/apt/sources.list && \
     echo "deb http://security.debian.org ${DEBIAN_RELEASE}/updates main contrib non-free"  >> /etc/apt/sources.list && \
    set -x &&\
    apt-get update