1. 查看和切換用戶
- 查看當前用戶
w
- 切換到用戶
user2
su - user2
- 切換到
root
sudo -i
2. 查看和切換shell
- 查看當前
shell
(默認是/bin/bash
)
echo $SHELL
- 切換到
/bin/zsh
(需要重啓終端)
chsh -s /bin/zsh
- 切換到
/bin/bash
(需要重啓終端)
chsh -s /bin/bash
3. 關於用戶shell的profile
加載順序:
# 系統級別
/etc/profile
/etc/paths
# 用戶級別
~/.bash_profile
~/.bash_login
~/.profile
~/.bashrc
前兩個是系統級別的環境變量,針對所有用戶,後面四個帶有~/用戶級別的環境變量。
前兩個環境配置在系統啓動時候就會加載。
~/.bash_profile
,~/.bash_login
,~/.profile
依次加載,如果~/.bash_profile
不存在,依次加載後面幾個文件;如果~/.bash_profile
文件存在,後面幾個文件不會加載
~/.bashrc
是bash shell
打開時候加載
全局環境變量設置
修改全局環境變量時候參考系統默認的環境變量配置格式。
修改全局環境變量需要root權限。
/etc/paths
全局建議修改這個文件
/etc/profile
不建議修改這個文件,全局共有配置,用戶登錄時候都會加載該文件
/etc/bashrc
一般在這個文件中添加系統級別的環境變量,全局共有配置,bash shell
執行時候都會加載
重新載入配置文件
執行以下指令立即生效
source <配置文件>
#示例
source .bash_profile