Linux開機檔案、設定環境變數的位置

來源:互聯網
上載者:User

Linux開機檔案、設定環境變數的位置 rc.local====================================1、 /etc/rc.local系統啟動需要載入的守護進程(服務)和執行的程式。該檔案只有一條“exit 0”語句,使用者可加入自己的啟動程式,但需要保證最後的返回是0。注意,該檔案中不能加入使用者shell下的指令碼,例如加入 alias ll="ls -l" 無效,因為該檔案的執行環境是在系統shell下,系統尚未進入使用者shell環境。 Linux系統開機檔案 - [Ubuntu]  (/etc/profile 、/etc/bashrc 、 ~/.profile 、 ~/bashrc 檔案)====================================(1)/etc/profile全域(公有)配置,不管是哪個使用者,登入時都會讀取該檔案。Mac 有此檔案 (2)/etc/bashrc全域(公有)配置,bash shell執行時,不管是何種方式,都會讀取此檔案。Mac 有此檔案 Ubuntu沒有此檔案,與之對應的是/ect/bash.bashrc (3)~/.bashrc當bash shell是以non-login形式執行時,讀取此檔案。若是以login形式執行,則不會讀取此檔案。當登入時以及每次開啟新的shell時,該該檔案被讀取.~/.bash_profile 與 ~/.bashrc  設定大致相同,所以通常前者會調用後者。 (4)~/.bash_profile若bash shell是以login方式執行時,才會讀取此檔案。該檔案僅僅執行一次!預設情況下,他設定一些環境變數,執行使用者的~/.bashrc檔案.~/.bash_profile 與 ~/.bashrc  設定大致相同,所以通常前者會調用後者。Mac 有此檔案(註:Linux 裡面是 .bashrc 而 Mac 是 .bash_profile)Unbutu預設沒有此檔案,可建立。 (5)~/.bash_login若bash shell是以login方式執行時,讀取~/.bash_profile,若它不存在,則讀取~/.bash_login,若前兩者不存在,讀取~/.profile。 (6)~/.profile若bash shell是以login方式執行時,讀取~/.bash_profile,若它不存在,則讀取~/.bash_login,若前兩者不存在,讀取~/.profile。另外,圖形模式登入時,此檔案將被讀取,即使存在~/.bash_profile和~/.bash_login。Mac 預設沒有此檔案,可手動建立此檔案 (7)~/.bash_logout登出時,且是longin形式,此檔案才會讀取。也就是說,在文字模式登出時,此檔案會被讀取,圖形模式登出時,此檔案不會被讀取。 下面是在本機(Ubuntu)的幾個例子====================================1. 圖形模式登入時,順序讀取:/etc/profile和~/.profile2. 圖形模式登入後,開啟終端時,順序讀取:/etc/bash.bashrc和~/.bashrc3. 文字模式登入時,順序讀取:/etc/bash.bashrc,/etc/profile和~/.bash_profile4. 從其它使用者su到該使用者,則分兩種情況:(1)如果帶-l參數(或-參數,--login參數),如:su -l username,則bash是lonin的,它將順序讀取以下設定檔:/etc/bash.bashrc,/etc/profile和~ /.bash_profile。(2)如果沒有帶-l參數,則bash是non-login的,它將順序讀取:/etc/bash.bashrc和~/.bashrc5. 登出時,或退出su登入的使用者,如果是longin方式,那麼bash會讀取:~/.bash_logout6. 執行自訂的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。 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.