Linux bashrc和profile的用途和区别
| 導(dǎo)讀 | 使用終端ssh登錄Linux操作系統(tǒng)的控制臺(tái)后,會(huì)出現(xiàn)一個(gè)提示符號(hào)(例如:#或~),在這個(gè)提示符號(hào)之后可以輸入命令,Linux根據(jù)輸入的命令會(huì)做回應(yīng),這一連串的動(dòng)作是由一個(gè)所謂的Shell來(lái)做處理。Shell是一個(gè)程序,最常用的就是Bash,這也是登錄系統(tǒng)默認(rèn)會(huì)使用的Shell。 |
用戶(hù)HOME(家)目錄/.bashrc
head -1 ~/.bashrc # ~/.bashrc: executed by bash(1) for non-login shells.用戶(hù)HOME(家)目錄/.profile
head -1 ~/.profile # ~/.profile: executed by Bourne-compatible login shells. ? 對(duì)于全部用戶(hù)的啟動(dòng)配置文件 head -1 /etc/bash.bashrc # System-wide .bashrc file for interactive bash(1) shells. head -2 /etc/profile # /etc/profile: system-wide .profile file for the Bourne shell (sh(1) # and Bourne compatible shells (bash(1), ksh(1), ash(1), ...). ? bashrc和profile的差異 從上面的英文描述可以知道,bashrc和profile的差異在于: 1. bashrc是在系統(tǒng)啟動(dòng)后就會(huì)自動(dòng)運(yùn)行。 2. profile是在用戶(hù)登錄后才會(huì)運(yùn)行。 3. 進(jìn)行設(shè)置后,可運(yùn)用source bashrc命令更新bashrc,也可運(yùn)用source profile命令更新profile。 PS:通常我們修改bashrc,有些linux的發(fā)行版本不一定有profile這個(gè)文件,本文用的系統(tǒng)是Ubuntu 15.10 4. /etc/profile中設(shè)定的變量(全局)的可以作用于任何用戶(hù),而~/.bashrc等中設(shè)定的變量(局部)只能繼承/etc/profile中的變量,他們是"父子"關(guān)系。 ? 補(bǔ)充介紹另外,需要補(bǔ)充說(shuō)明介紹bashrc相關(guān)的幾個(gè)文件:
~/.bash_profile: 每個(gè)用戶(hù)都可使用該文件輸入專(zhuān)用于自己使用的shell信息,當(dāng)用戶(hù)登錄時(shí),該文件僅僅執(zhí)行一次!默認(rèn)情況下,他設(shè)置一些環(huán)境變量,執(zhí)行用戶(hù)的.bashrc文件。
~/.bash_logout: 當(dāng)每次退出系統(tǒng)(退出bash shell)時(shí),執(zhí)行該文件。
~/.bash_profile 是交互式、login方式進(jìn)入bash運(yùn)行的,~/.bashrc是交互式non-login方式進(jìn)入bash運(yùn)行的,通常二者設(shè)置大致相同,所以通常前者會(huì)調(diào)用后者。
本文轉(zhuǎn)載自:http://www.linuxprobe.com/linux-bashrc-profile-different.html
更多Linux干貨請(qǐng)?jiān)L問(wèn):http://www.linuxprobe.com/
轉(zhuǎn)載于:https://www.cnblogs.com/probemark/p/5886766.html
總結(jié)
以上是生活随笔為你收集整理的Linux bashrc和profile的用途和区别的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Linux 共享内存详解一
- 下一篇: linux命令学习-1-less