2015年9月17日 星期四

[Linux 常見問題] How to know if the running platform is Ubuntu or CentOS?

Source From Here 
Question 
I know the commands to check the name of the Linux machine running on my machine. For example: 
- Ubuntu 
# uname -a
Linux ubuntu 3.19.0-25-generic #26~14.04.1-Ubuntu SMP Fri Jul 24 21:16:20 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

- CentOS 
# rpm -qa \*-release\* | grep centos
centos-release-7-1.1503.el7.centos.2.8.x86_64

How do I get the output from the terminal and compare to see if it is UBUNTU or CENTOS and perform the following commands? 
# apt-get install updates

Or 
# yum update

How-To 
My recommendation is to use this command instead: 
# python -mplatform | grep Ubuntu && sudo apt-get update || sudo yum update

python platform module will work on both systems, the rest of the command will check if Ubuntu is returned by python and run apt-get else yum.

沒有留言:

張貼留言

[JS 文章收集] 用 Node.js 學 JavaScript 語言(1)簡介與安裝

Source From  Here   簡介   Node.js  是 Ryan Dahl 基於 Google 的 V8 引擎於 2009 年釋出的一個 JavaScript 開發平台,主要聚焦於 Web 程式的開發,通常用被來寫網站。但是,要開發網站就勢必要把「 HTML,...