`

shell的初始化文件:/etc/profile和/etc/bashrc(bash.bashrc)

阅读更多
(1)/etc/profile   登录时,会执行。
全局(公有)配置,不管是哪个用户,登录时都会读取该文件。
(2)/ect/bashrc   Ubuntu没有此文件,与之对应的是/ect/bash.bashrc
bash.bashrc 是交互式shell的初始化文件。 
(3)~/.profile  某个用户读取的配置。
若bash是以login方式执行时,读取~/.bash_profile,若它不存在,则读取~/.bash_login,若前两者不存在,读取~ /.profile。
另外,图形模式登录时,此文件将被读取,即使存在~/.bash_profile和~/.bash_login。
(4)~/.bash_login  
若bash是以login方式执行时,读取~/.bash_profile,若它不存在,则读取~/.bash_login,若前两者不存在,读取~ /.profile。
(5)~/.bash_profile   Unbutu默认没有此文件,可新建。
只有bash是以login形式执行时,才会读取此文件。通常该配置文件还会配置成去读取~/.bashrc。
(6)~/.bashrc     该文件包含专用于某个用户的bash shell的bash信息,当该用户登录时以及每次打开新的shell时,该文件被读取.
当bash是以non-login形式执行时,读取此文件。若是以login形式执行,则不会读取此文件。
(7)~/.bash_logout
注销时,且是longin形式,此文件才会读取。也就是说,在文本模式注销时,此文件会被读取,图形模式注销时,此文件不会被读取。

补充一点,/etc/rc.local是系统shell会执行的文件,linux启动后会退出的;/etc/profile 或 /etc/bash.bashrc是用户shell会的配置,我们一般的Shell是用户Shell的子进程,而非系统shell的子进程,所以如果在/etc/rc.local中指定"alias ll='ls -a'"这样的别名,对登录系统后的shell是没用的。

某网友总结如下:
/etc/profile,/etc /bashrc 是系统全局环境变量设定 
/etc/profile与/etc/bashrc的区别?
前一个主要用来设置一些系统变量,比如JAVA_HOME等等,后面一个主要用来保存一些bash的设置. 
~/.profile,~/.bashrc用户家目录下的私有环境变量设定
当登入系统时候获得一个shell进程时,其读取环境设定档有三步
1 首先读入的是全局环境变量设定档/etc/profile,然后根据其内容读取额外的设定的文档,如
/etc/profile.d和/etc/inputrc
2 然后根据不同使用者帐号,去其家目录读取~/.bash_profile,如果这读取不了就读取~/.bash_login,这个也读取不了才会读取
~/.profile,这三个文档设定基本上是一样的,读取有优先关系
3 然后在根据用户帐号读取~/.bashrc
至于~/.profile与~/.bashrc的区别,都具有个性化定制功能
~/.profile可以设定本用户专有的路径,环境变量,等,它只能登入的时候执行一次
~/.bashrc也是某用户专有设定文档,可以设定路径,命令别名,每次shell script的执行都会使用它一次


下面是几个例子:
1. 图形模式登录时,顺序读取:/etc/profile和~/.profile
2. 图形模式登录后,打开终端时,顺序读取:/etc/bash.bashrc和~/.bashrc
3. 文本模式登录时,顺序读取:/etc/bash.bashrc,/etc/profile和~/.bash_profile
4. 从其它用户su到该用户,则分两种情况:
    (1)如果带-l参数(或-参数,--login参数),如:su -l username,则bash是lonin的,它将顺序读取以下配置文件:/etc/bash.bashrc,/etc/profile和~ /.bash_profile。
    (2)如果没有带-l参数,则bash是non-login的,它将顺序读取:/etc/bash.bashrc和~/.bashrc
5. 注销时,或退出su登录的用户,如果是longin方式,那么bash会读取:~/.bash_logout
6. 执行自定义的shell文件时,若使用“bash -l a.sh”的方式,则bash会读取行:/etc/profile和~/.bash_profile,若使用其它方式,如:bash a.sh, ./a.sh,sh a.sh(这个不属于bash shell),则不会读取上面的任何文件。
7. 上面的例子凡是读取到~/.bash_profile的,若该文件不存在,则读取~/.bash_login,若前两者不存在,读取~ /.profile。

参考资料:
http://hi.baidu.com/id_joyride/blog/item/aaa7483f38cf073471cf6ce5.html/cmtid/6f67a6224362a649ac34de1a
http://hi.baidu.com/fjfhwfn2007/blog/item/8d9743951625cc047bf48099.html
http://hi.baidu.com/mydreamleaf/blog/item/343aa3fbc596f816a8d31152.html

转自:http://www.51testing.com/?uid-225738-action-viewspace-itemid-216622
分享到:
评论

相关推荐

    浅析linux 下的/etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc

    浅析linux 下的/etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc

    mac 安装omyzsh后不执行~/.bash_profile、~/.bashrc的完美解决办法

    source ~/.bash_profile、~/.bashrc等脚本文件就ok了 以上所述是小编给大家介绍的mac 安装omyzsh后不执行~/.bash_profile、~/.bashrc的完美解决办法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会...

    ubuntu配置文件备份

    ~/.bashrc:/etc/profile:/etc/vim/vimrc:/etc/bash.bashrc

    Linux中profile、bashrc、bash_profile之间的区别和联系

    .profile(由Bourne Shell和Korn Shell使用)和.login(由C Shell使用)两个文件是.bash_profile的同义词,目的是为了兼容其它Shell。在Debian中使用.profile文件代 替.bash_profile文件。 2..bashrc文件会在bash shell...

    .bash_profile和.bashrc的什么区别

    详细介绍.bash_profile和.bashrc有什么区别

    Linux 中环境变量设置.docx

     /etc/bashrc: 为每一个运行 bash shell 的用户执行此文件。当 bash shell 被打开时,该文件被读取。  ~/.bash_profile: 每个用户都可使用该文件输入专用于自己使用的 shell 信息,当用户登录时,该文件仅仅执行一...

    gitbash:更好的git使用bash设置

    例如 cd ~/.bash/git clone https://github.com/mocheng/gitbash然后,在您的~/.bashrc ,添加以下行 source ~/.bash/gitbash/git-prompt.shPS1="\u@:\w\[\e[1;32m\]\$(parse_git_branch_or_tag)\[\e[0m\]$"现在,...

    profile\bashrc\bash_profile之间的区别和联系

    /etc/bashrc 每个运行bash shell的用户都执行此文件,当bsh被打开时,该文件被读取; ~/.bash_profile 专用于本用户的shell信息,仅被执行一次; ~/.bashrc 文件包含本用户的bsh信息,登录及每次打开shell时被读取。

    bashprofile与bashrc.doc

    /etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行. 并从/etc/profile.d目录的配置文件中搜集shell的设置.

    Linux 添加开机启动方法(服务/脚本)

    /etc/profile、/root/.bash_profile /etc/bashrc、/root/.bashrc /etc/profile.d/*.sh、/etc/profile.d/lang.sh /etc/sysconfig/i18n、/etc/rc.local(/etc/rc.d/rc.local) 一、修改开机启动文件:/etc/rc.local...

    Bash-Extend:用于扩展bashrc并节省您时间的示例别名

    /etc/bash.bashrc_extend" >> /etc/bash.bashrc;source /etc/bash.bashrc 更新 update_bashrc_extend 去掉 remove_bashrc_extend 例子 aptu = aptitude update;aptitude upgrade; updatey = apt-get --yes update &...

    AwesomeCustomBashProfile

    ~/.bash_ultrawalkerfi~/.bashrc 文件可能因您的发行版而异,请记住.bashrc 包含在所有其他文件中,例如 .bash_profile /etc/bash.bashrc 包含在 .bashrc 中,所以/etc/bash.bashrc > ~/.bashrc > ~/.bash_profile

    bashrc.d:Bash Shell的APLv2许可启动脚本框架

    bashrc.d “ bashrc.d”是Bash shell的APLv2许可的启动脚本框架。 。快速开始分叉此存储库(到“您的仓库”)。 将分叉的存储~/.bashrc.d到~/.bashrc.d目录中: git clone git@github.com:your-repo/bashrc.d.git ~/...

    dotfiles:我的点文件

    配置文件 这是我的点文件的存储库。 很棒的配置:〜/ .config / awesome bashrc:〜/ .bashrc crontab:crontab -l >> crontab.txt JS美化工具:〜/ .jsbeautifyrc git-buildpackage conf:〜/ .gbp.conf git...

    libcusparse.so.11

    安装torch-geometric和安装torch-sparse后,导入torch-sparse时却报错: OSError: libcusparse.so.11: cannot open shared object file: No such file or directory 搜索全网,也没找到解决方案。最快解决方案如下:...

    ROS控制Turtlebot3移动机器人的基础教程

    需要注意的是ROS需要IP地址在turtlebot和远程PC之间进行通信 修改.bashrc nano ~/.bashrc PC端配置 export ROS_MASTER_URI=http://PC端IP:11311 export ROS_HOSTNAME=PC端IP Turtlebot端配置 export ROS_MAS

    Linux 环境变量详解及实例

    Linux环境变量 ~/.bash_profile && ~/.bashrc ... 如果”~/.bash_login”和”~/.profile”文件存在的时候也会在执行。 下面看看”~/.bash_profile”文件里面有什么东西 $cat ~/.bash_profile # .bash_profile # Get

    Linux配置java.doc

    linux在启动过程中,会先执行/etc/profile文件,然后执行用户目录下的~/.bash_profile、~/bash_login、~/.profile中的其中一个(执行优先级为从左到右)。如果~/.bash_profile文件存在的话,一般还会执行~/.bashrc。...

    bashrc:用于系统部署的跨平台 bash 配置

    只需使用函数将代码包装在${HOME}/.bash_profile ,如下所示: bl () { if [[ -s " ${HOME} /.bash/bashrc " ]] ; then bashrc_local_install=1 bashrc_prefix= " ${HOME} /.bash " export ba

Global site tag (gtag.js) - Google Analytics