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

设置变量的三种方法
1) 在/etc/profile文件中添加变量【对所有用户生效(永久的)】
2) 在用户目录下的.bash_profile文件中增加变量【对单一用户生效(永久的)】
例如:编辑wangbin用户目录(/home/guok)下的.bash_profile
$ vi /home/wangbin/.bash.profile
3) 直接运行export命令定义变量【只对当前shell(BASH)有效(临时的)】
#export NAME=”yuan faxiang”


/etc/profile 系统相关的配置文件,针对所有用户
内设PATH,USER,LOGNAME,MAIL,INPUTRC,HOSTNAME,HISTSIZE,umask,export全局声明等等。
etc/profile里面的声明
# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.
#cd /etc/profile.d/
#vim path.sh 【.sh 表示这是个配置文件】
写入
#!/bin/bash
export PATH=$PATH:/tmp/:/date/bin
退出
#source /etc/profile

/etc/bashrc 系统级别的变量,针对所有shell,所有用户
bashrc里面的声明,和/etc/profile里面的声明一样
# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.

主要预设umask以及PS1。PS1是敲命令时,前面那串字符。例如CentOS root用户默认PS1是 [root@localhost~]#。

#echo $PS1
[\u@\h \W]\$ 【h后面要有空格】
u 用户
h 主机名
W 当前目录的缩写目录 可以更改为小写w,表示当前路径的绝对路径
$ 符号 #

#PS1='[\u@\h \w]\$' 显示绝对路径


更改umask
#umask
0022
#vim /etc/profile.d/umask.sh
!# /bin/bash
umask 0012
#source /etc/profile
#umask
0012
上述是两个系统级别的配置文件,每个用户的家目录下还有几个隐藏文件
#ls -la . |grep bash
.bash_profile 定义当前用户环境变量PATH
定义用户个人化路径与环境变量的文件名称。每个用户都可使用该文件输入专用于自己使用的shell信息,当用户登陆时,该文件仅仅执行一次。

.bashrc 定义当前用户别名
包含专用于你的shell的bash信息,当登陆时以及每次打开新的shell时,文件被读取。可以讲用户自定义的alias或者自定义变量写到文件中。

.bash_history
记录命令历史

.bash_logout
退出shell时候,会执行该文件。建议把清理工作放到此文件中。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值