linux下文件/etc/profile、/etc/bashrc、~/.bashrc 和~/.bash_profile文件的區別 && 用戶登錄后的加載配置文件的順序


//整理一些關於環境變量的筆記,方便以后回顧

1、環境變量配置原因

環境變量:指定一個目錄,運行軟件或程序的時候,相關程序會按照目錄尋找相關文件

原因:使你可以在非安裝目錄運行軟件

2、環境變量的設置方法

(1) 控制台,僅臨時有效,僅針對於當前shell

  • $PATH="$PATH:/opt/tomcat"

 

 

需要給某個用戶權限只需要在其個人主目錄想修改即可。修改方法類似於/etc/profile文件

3、~/.bashrc、~/.bash_profile、~/.bash.profile和/etc/bashrc和/etc/profile的區別

 

 

 

 

 

1 # /etc/profile
2 
3 # System wide environment and startup programs, for login setup
4 # Functions and aliases go in /etc/bashrc
5 
6 # It's NOT a good idea to change this file unless you know what you
7 # are doing. It's much better to create a custom.sh shell script in
8 # /etc/profile.d/ to make custom changes to your environment, as this
9 # will prevent the need for merging in future updates.

 

②/ etc / bashrc:
  為每一個運行bash shell的用戶執行此文件,當bash shell被打開時,該文件被讀取。也就是說,當用戶shell執行了bash時,運   行這個文件。

1 # /etc/bashrc
2 
3 # System wide functions and aliases
4 # Environment stuff goes in /etc/profile
5 
6 # It's NOT a good idea to change this file unless you know what you
7 # are doing. It's much better to create a custom.sh shell script in
8 # /etc/profile.d/ to make custom changes to your environment, as this
9 # will prevent the need for merging in future updates.

③〜/ .bashrc 該文件存儲的是專屬於個人bash shell的信息,當登錄時以及每次打開一個新的shell時,執行這個文件。在這個文件里可以自定義用戶專屬的個人信息。

④~/.bash_profile:每個用戶都可使用該文件輸入專用於自己使用的shell信息,當用戶登錄時,該 文件僅僅執行一次!默認情況下,他設置一些環境變量,執行用戶的.bashrc文件.

1、在登錄時,操作系統定制用戶環境時使用的第一個文件就是  /etc/profile  ,此文件為系統的每個用戶設置環境信息,當用戶第一次登錄時,該文件被執行。
2、在登錄時操作系統使用的第二個文件是  /etc/environment  ,系統在讀取你自己的profile  前,設置環境文件的環境變量。
3、在登錄時用到的第三個文件是.profile文件,每個用戶都可使用該文件輸入專用於自己使用的shell信息,,該 文件僅僅執行一次!默認情況下,他設置一些環境變量,執行用戶的.bashrc文件。/etc/bashrc:為每一個運行bash shell的用戶執行此文件。當bash shell 被打開時,該文件被讀取。


免責聲明!

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



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