1.如何查询linux 是Ubuntu还是centos系统?
第一种方法:
# lsb_release -a
LSB Version: :core-4.0-ia32:core-4.0-noarch:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-ia32:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 5.7 (Final)
Release: 5.7
Codename: Final
这个命令适用于所有遵守LSB规范的的linux,包括Redhat、SuSE、Debian、Ubuntu、Centos等发行版。
接下来的命令虽不能查看当前系统名和版本,但可以显示系统核心信息。
root@MyMail ~ # uname
Linux
root@MyMail ~ # uname -r
2.6.18-164.el5
[root@localhost ~]# uname -a
Linux localhost.localdomain 2.6.18-194.el5 #1 SMP Fri Apr 2 14:58:35 EDT 2010 i686 i686 i386 GNU/Linux
以下二种方法适用于RedHat、CentOS
root@MyMail ~ # cat /etc/redhat-release
CentOS release 5.7 (Final)
登录到linux执行:
#rpm -q redhat-release
或CentOS执行:
root@MyMail ~ # rpm -q centos-release
centos-release-5-7.el5.centos.1
第四种方法:
当前centos 版本与redhat对应的版本的命令
这个命令在centos下并不准确,显示的系统和版本也是Red Hat 3.4.6-10。
# cat /proc/version
Linux version 2.6.9-78.ELsmp (mockbuild@builder16.centos.org) (gcc version 3.4.6 20060404 (Red Hat 3.4.6-10)) #1 SMP Fri Jul 25 00:04:28 EDT 2008
而此命令在Ubuntu上使用,显示中智能看出是Ubuntu,但看不出版本。
最后一种方法:
#cat /etc/issue
在CentOS下执行显示为:
CentOS release 5.7 (Final)
Kernel \r on an \m
或在Ubuntu下显示为:
Ubuntu 11.04 \n \l
可以用来查看当前正在运行的 Ubuntu 的版本号
2.在命令行执行export命令有效,但是写在shell 脚本中,直接执行shell 脚本不生效?
使用source xxx.sh
执行即可
原因:当在终端shell中执行一个sh 脚本,本质是创建一个子进程来执行sh脚本中的命令,当export时,变量加入子进程的环境变量(而非父进程shell)。当脚本执行结束,子进程销毁。返回父进程,父进程的环境变量没有任何变化。
如果希望嵌入Linux启动时加入的环境变量,可以直接将export的环境变量添加到/etc/profile(该文件中的环境变量是适用于所有用户的全局变量)
若希望在Ubuntu上为特定的用户添加环境变量,可以在~/.bashrc文件中添加
参考链接:
https://blog.csdn.net/dufufd/article/details/75330595
https://blog.csdn.net/namelcx/article/details/16902359