您的位置:首页 > 其它

系统和用户的环境变量配置文件

2017-01-12 14:28 218 查看
用来规定环境变量的配置文件 /etc/profile,它表示系统相关的环境变量
注:不过要想改变某些环境变量的话,最好在/etc/profile.d/下面去定义,写自己的shell 。
最好不要更改/etc/profile文件。
比如定义个path.sh
[root@wy ~]# vim /etc/profile.d/path.sh
#!/bin/bash
export PATH=$PATH:/tmp/:/data/bin/ #自己新定义的PATH
重置并生效
[root@wy ~]# source /etc/profile
[root@wy ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/tmp/:/data/bin/
另外一个配置文件/etc/bashrc,会定义PS1,umask(/etc/profile文件里也有定义)
注:这个文件最好也不要修改;最好在/etc/profile.d/下面去定义,写自己的shell

查看PS1
[root@wy ~]# echo $PS1 #PS1定义的我们命令的前缀
[\u@\h \W]\$
修改PS1,把W换成w,区别就是w会显示绝对路径,而W会显示路径的最后一段
[root@wy ~]# PS1='[\u@\h \w]\$ '
[root@wy ~]# cd /etc/init.d/
[root@wy /etc/init.d]#
[root@wy /etc/init.d]# PS1='[\u@\h \W]\$ '
[root@wy init.d]# cd /etc/init.d/
[root@wy init.d]#
还可以加上时间\t
[root@wy init.d]# PS1='[\u@\h\t \W]\$ '
[root@wy19:29:31 init.d]#
root用户是# 普通用户是$
[root@wy ~]# su - wyy
[wyy@wy ~]$

/etc/profile、/etc/bashrc是关于系统级别的。除了这两个之外,还有一些在用户的家目录下,可以用 ls -la .
可以看到有几个以.bash开头的。 .bash_profile文件和我们系统的/etc/profile文件是一类文件,很像。/etc/profile
作一个全局的,任何用户都能用到的这样的一个配置文件;若想针对用户自己来定义一些环境变量,可以在这个
.bash_profile里去定义。
.bashrc这个里面会定义用户的别名,当用户登录时以及每次打开新的shell时执行该文件。

注: .bashrc会被.bash_profile调用
如果在.bashrc里面定义了变量,然后又在.bash_profile里面unset该变量,那么当我们登录一个终端时,echo该变量的值为空
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息