目錄
- 一.關于linux組態檔
- 二.驗證四個組態檔的加載順序
- 三.結論
一.關于linux組態檔
1.linux下主要有四個組態檔:/etc/profile 、/etc/bashrc 、/root/.bashrc 、/root/.bash_profile,
- ? /etc/profile 設定的是系統全域環境和登錄系統的一些配置,該配置對所有用戶生效;
- ? /etc/bashrc 是shell 全域自定義組態檔,主要用于自定義 shell,該配置對所有用戶的shell都生效;
- ? /root/.bashrc 用于單獨自定義root用戶的 bash,只對root用戶的bash生效,如果要使elk用戶生效,則需要配置/home/elk/.bashrc檔案;
- ? /root/.bash_profile 用于單獨自定義root用戶的系統環境,只對root用戶生效,如果要使elk用戶生效,則需要配置/home/elk/.bash_profile,
2./etc/profile 、/etc/bashrc這兩個組態檔是全域組態檔,對所有用戶生效;/username/.bashrc 、/username/.bash_profile是區域
組態檔,只對單個用戶生效,
3.舉個最簡單的例子:一個專案中需要你配置java環境,如果java環境只是elk用戶用到,其他用戶壓根用不到,此時就把java環境配置
在/home/elk/.bash_profile里;但是如果你這個專案是java web專案,所有的服務都是基于java環境的,此時你就需要把java配置
到/etc/profile里面,省得去每個用戶下面配置;如果elk用戶想對自己的一些常規操作設定別名,但是又不想影響別人,就可以把別名設
置在/home/elk/.bashrc里面;如果系統管理員想設定bash的代碼補全,bash的顏色,并且對所有的用戶生效,則需要配置
在/etc/bashrc里面
二.驗證四個組態檔的加載順序
1.現在就衍生出一個問題,當我們登錄系統或者系統開機時,這四個組態檔的加載順序是怎樣的?
2.解題思路:在這四個組態檔的末尾追加一行"echo "this is ****"",然后登錄系統,看echo輸出順序就知道四個組態檔的加載順序了,
3.現在開始證明,以root用戶為例:
#在每個組態檔末尾追加echo "this is *****"
[root@node5 ~]# echo "echo "this is /etc/profile"" >> /etc/profile
[root@node5 ~]# echo "echo "this is /etc/bashrc"" >> /etc/bashrc
[root@node5 ~]# echo "echo "this is /root/.bashrc"" >> /root/.bashrc
[root@node5 ~]# echo "echo "this is /root/.bash_profile"" >> /root/.bash_profile
#現在斷開連接,使用root用戶登錄系統
Connection closed.
Disconnected from remote host(node5) at 10:23:38.
Type `help' to learn how to use Xshell prompt.
[c:\~]$
Connecting to 192.168.110.184:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
WARNING! The remote SSH server rejected X11 forwarding request.
Last login: Mon Dec 14 09:14:27 2020 from 192.168.110.1
this is /etc/profile
this is /etc/bashrc
this is /root/.bashrc
this is /root/.bash_profile
三.結論
從2.3步的輸出不難看出,當登錄系統或者新開啟一個 ssh連接啟動 bash 行程時,這四個組態檔的加載順序如下:
- ? /etc/profile > /etc/bashrc > /root/.bashrc > /root/.bash_profile
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/234574.html
標籤:其他
上一篇:S3C2440從NAND Flash啟動和NOR FLASH啟動的問題
下一篇:Linux系統的目錄及作用
