Linux bashrc和profile的用途和區別


導讀 使用終端ssh登錄Linux操作系統的控制台后,會出現一個提示符號(例如:#或~),在這個提示符號之后可以輸入命令,Linux根據輸入的命令會做回應,這一連串的動作是由一個所謂的Shell來做處理。Shell是一個程序,最常用的就是Bash,這也是登錄系統默認會使用的Shell。

Linux bashrc和profile的用途和區別Linux bashrc和profile的用途和區別

• 對於個別用戶的啟動配置文件

用戶HOME(家)目錄/.bashrc

head -1 ~/.bashrc # ~/.bashrc: executed by bash(1) for non-login shells. 

用戶HOME(家)目錄/.profile

head -1 ~/.profile # ~/.profile: executed by Bourne-compatible login shells. 
• 對於全部用戶的啟動配置文件
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是在系統啟動后就會自動運行。 2. profile是在用戶登錄后才會運行。 3. 進行設置后,可運用source bashrc命令更新bashrc,也可運用source profile命令更新profile。 PS:通常我們修改bashrc,有些linux的發行版本不一定有profile這個文件,本文用的系統是Ubuntu 15.10 4. /etc/profile中設定的變量(全局)的可以作用於任何用戶,而~/.bashrc等中設定的變量(局部)只能繼承/etc/profile中的變量,他們是"父子"關系。 
• 補充介紹

另外,需要補充說明介紹bashrc相關的幾個文件:
~/.bash_profile: 每個用戶都可使用該文件輸入專用於自己使用的shell信息,當用戶登錄時,該文件僅僅執行一次!默認情況下,他設置一些環境變量,執行用戶的.bashrc文件。
~/.bash_logout: 當每次退出系統(退出bash shell)時,執行該文件。
~/.bash_profile 是交互式、login方式進入bash運行的,~/.bashrc是交互式non-login方式進入bash運行的,通常二者設置大致相同,所以通常前者會調用后者。

本文轉載自:http://www.linuxprobe.com/linux-bashrc-profile-different.html

更多Linux干貨請訪問:http://www.linuxprobe.com/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM