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.

沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...