1 /etc/profile
用于设置系统级的环境变量和启动程序,在这个文件下配置会对所有用户生效。当用户登入(login)时,文件会被执行,并从/etc/profile.d目录的配置文件中查找shell设置。一般不建议在/etc/profile文件中添加环境变量,因为在这个文件中添加的设置会对所有用户起作用。
2 ~/.bash_profile
该文件是一个用户级的设置,这个文件同样也可以用于配置环境变量和启动程序,但只针对单个用户有效。和/etc/profile文件类似,bash_profile也会在用户登录(login)时生效,也可以用于设置环境变量。但与profile不同,bash_profile只会对当前用户生效。
$ cat ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
//'#'表示注释,上面这三行代码表示若存在~/.bashrc,则读入~/.bashrc的设置
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH=$PATH:/usr/local/bin //在这里可以添加变量
export PATH=$PATH:/opt/buildroot-2012.08/arm920t/usr/bin
export PATH=$PATH:/usr/local/git/bin
由于/etc/profile和~/.bash_profile都是在取得login shell的时候才会读取的配置文件,所以如果你将自己的偏好设置写入~/.bashrc文件后,通常要重启后/etc/profile和~/.bash_profile才能生效,若不想重启,则需要读入环境配置文件的命令source。
e.g source ~/.bashrc 表示将~/.bashrc的配置读入~/.bash_profile中
3 ~/.bashrc和/etc/bashrc
这个两个文件用于配置函数或别名,/etc/bashrc是系统级的、~/.bashrc是用户级的,两者分别会对所有用户和当前用户生效。
$ cat ~/.bashrc
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
//同上理这里表示若存在/etc/bashrc,则读入/etc/bashrc的配置
# User specific aliases and functions
alias vt100='export TERM=vt100' //在这里可以为常用命令定义别名
alias linux='export TERM=linux'
alias la='ls -a'
alias gitci='git commit'
alias gitpush='git push origin master'
4. 主线如下:
开机——>读取/etc/profile(系统配置)——>读取~/.bash_profile(用户配置)——>开始操作bash
对于~/.bash_profile这条分支:
~/.bash_profile<——~/.bashrc<——/etc/bashrc
通常来说,作为一般用户我们只要修改~/.bashrc和~/.bash_profile,之后source.