bashrc和profile的用途和區別

2021-09-08 12:30:23 字數 1323 閱讀 6928

使用終端登入linux作業系統的控制台後,會出現乙個提示符號(例如:#或~),在這個提示符號之後可以輸入命令,linux根據輸入的命令會做回應,這一連串的動作是由乙個所謂的shell來做處理。

shell是乙個程式,最常用的就是bash,這也是登入系統缺省會使用的shell。

bashrc和profile都是shell的啟動設定檔案(其實這兩個檔案也是shell指令碼),可以為當前的shell初始化環境變數等,它們類似microsoft dos/windows下的autoexec.bat檔案。

下面詳細介紹bashrc和profile的用途和區別:

1. 針對個別使用者

使用者home(家)目錄/.bashrc

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

使用者home(家)目錄/.profile

# ~/.profile: executed by bourne-compatible login shells.

2. 針對全體使用者

/etc/bash.bashrc

# system-wide .bashrc file for interactive bash(1) shells.

/etc/profile

# /etc/profile: system-wide .profile file for the bourne shell (sh(1))

從上面的英文描述可以知道,bashrc和profile的差異在於:

1. bashrc是在系統啟動後就會自動執行。

2. profile是在使用者登入後才會執行。

3. 進行設定後,可運用source bashrc命令更新bashrc,也可運用source profile命令更新profile。

ps:通常我們修改bashrc,有些linux的發行版本不一定有profile這個檔案

4. /etc/profile中設定的變數(全域性)的可以作用於任何使用者,而~/.bashrc等中設定的變數(區域性)只能繼承/etc/profile中的變數,他們是"父子"關係。

~/.bash_profile: 每個使用者都可使用該檔案輸入專用於自己使用的shell資訊,當使用者登入時,該檔案僅僅執行一次!預設情況下,他設定一些環境變數,執行使用者的.bashrc檔案。

~/.bash_logout: 當每次退出系統(退出bash shell)時,執行該檔案。

~/.bash_profile 是互動式、login方式進入bash執行的,~/.bashrc是互動式non-login方式進入bash執行的,通常二者設定大致相同,所以通常前者會呼叫後者。

Linux中 bashrc和profile的區別

之前安裝qt 4.7.2,由於習慣了在命令列下編譯原始檔,我在網上搜了一下關於qt環境變數的配置方法,配置很簡單,在 etc profile檔案裡新增下面幾行語句 export qtdir opt qtsdk 2010.05 qt 這個路徑根據自己安裝的位置進行配置 export ld librar...

Linux下profile和bashrc的區別

在做環境變數配置時涉及到了這兩個檔案,故在網上找了一下它們之間的區別,記錄下來方便以後查閱 bashrc與profile的區別 從上面的英文描述可以知道,bashrc和profile的差異在於 1.bashrc是在系統啟動後就會自動執行。2.profile是在使用者登入後才會執行。3.進行設定後,可...

Linux下profile和bashrc四種的區別

etc profile etc bashrc bash profile bashrc很容易混淆,他們之間有什麼區別?它們的作用到底是什麼?1 etc profile 用來設定系統環境引數,比如 path.這裡面的環境變數是對系統內所有使用者生效的。2 etc bashrc 這個檔案設定系統bash ...