Linux安裝時可能要修改的配置文件:/etc/profile、/etc/bashrc(ubuntu沒有這個文件,對應地,其有/etc/bash.bashrc文件。我用的是ubuntu系統,所以下面將一律使用/etc/bash.bashrc來敘述)、~/.bash_profile、~/.bash_login、~/.profile、~/.bashrc。
utuntu系統默認只有/etc/profile、/etc/bash.bahsrc、~/.profile、~/.bashrc這四個文件。其他文件可以創建。
1 /etc/profile
用於設置系統級的環境變量和啟動程序
2 ~/.profile
該文件是一個用戶級的設置,這個文件同樣也可以用於配置環境變量和啟動程序,但只針對單個用戶有效
3 ~/.bashrc和/etc/bashrc(/etc/bash.bahsrc)
這個兩個文件用於配置函數或別名,/etc/bashrc是系統級的、~/.bashrc是用戶級的,兩者分別會對所有用戶和當前用戶生效。
讀取順序:
在4個文件中加入 echo 語句測試
切換管理員
eko@ubuntu:~$ su - Password: here is /etc/bash.bashrc here is /etc/profile
切換用戶
root@ubuntu:~# su - 'eko' here is /etc/bash.bashrc here is /etc/profile here is /eko/.bashrc here is /eko/.profile
可見登錄式Shell執行順序是:
/etc/.bashrc --> /etc/profile --> ~/.bashrc --> ~/.profile
非登錄式Shell
eko@ubuntu:~$ su Password: here is /etc/bash.bashrc
root@ubuntu:/home/eko# su 'eko' here is /etc/bash.bashrc here is /eko/.bashrc
/etc/bash.bashrc --> ~/.bashrc