我试图通过一个简单的命令通过/ etc / os-release文件在一行上获得OS名称(pretty_name)和版本(version_ID)。
目前,我有以下内容:
cat /etc/*-release | egrep "PRETTY_NAME|VERSION_ID" | cut -d = -f 2 | tr -d '"'
这给了我以下输出:
7.9
Red Hat Enterprise Linux
我希望获得如下输出:
Red Hat Enterprise Linux 7.9
我该怎么做才能获得想要的输出?
注意; 内容的顺序/etc/*-release
无法保证。这个答案集中在OP的案例上。
使用tac
扭转输出,那么使用tr '\n' ' '
以连接线;
cat /etc/*-release | egrep "PRETTY_NAME|VERSION_ID" | cut -d = -f 2 | tr -d '"' | tac | tr '\n' ' '
# 10 Debian GNU/Linux 10 (buster)
另一种选择是读取lsb_release
女巫的第二行和第三行具有更一致的输出;
lsb_release -as 2>/dev/null | sed -n 2,3p | tac | tr '\n' ' '
# 10 Debian GNU/Linux 10 (buster)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句