Linux下文件 ~/.bashrc 和 ~/.bash_profile 和 /etc/bashrc 和 /etc/profile 的區別 | 用戶登錄後加載配置文件的順序
阿新 • • 發佈:2018-04-20
用戶登錄 details 文件中 設定 tail 配置文件 https 說明 終端
- 轉自 https://blog.csdn.net/secondjanuary/article/details/9206151
- 文件說明:
- /ect/profile
- 此文件為系統的每個用戶設置環境信息,當用戶第一次登錄時,該文件被執行.並從/etc/profile.d目錄的配置文件中搜集shell的設置.
- /etc/bashrc
- 為每一個運行bash shell的用戶執行此文件.當bash shell被打開時,該文件被讀取.
- ~/.bash_profile
- 每個用戶都可使用該文件輸入專用於自己使用的shell信息,當用戶登錄時,該文件僅僅執行一次!默認情況下,他設置一些環境變量,執行~/.bashrc文件.
- ~/.bashrc
- 該文件包含專用於用戶的bash shell的bash信息,當登錄時以及每次打開新的shell時,該該文件被讀取.
- ~/.bash_logout
- 當每次退出系統(退出bash shell)時,執行該文件.
- /ect/profile
- 另外, /etc/profile 中設定的變量(全局)的可以作用於任何用戶
- 而~/.bashrc等中設定的變量(局部)只能繼承 /etc/profile 中的變量,他們是"父子"關系.
- 用戶登錄後加載配置文件的順序:
- /etc/profile-------->/etc/profile.d/*.sh
- ~/.bash_profile-------->~/.bashrc---------->/etc/bashrc
- 說明:
- bash首先執行 /etc/profile 腳本,/etc/profile 腳本先依次執行 /etc/profile.d/*.sh
- 隨後bash會執行 ~/.bash_profile 腳本, ~/.bash_profile腳本會執行~/.bashrc腳本,而~/.bashrc腳本會執行/etc/bashrc腳本
- 至此,所有的環境變量和初始化設定都已經加載完成
- bash隨後會調用terminfo和inputrc,分別完成終端屬性和鍵盤映射的設定
Linux下文件 ~/.bashrc 和 ~/.bash_profile 和 /etc/bashrc 和 /etc/profile 的區別 | 用戶登錄後加載配置文件的順序