環境變量配置文件目錄概要
- /etc/profile 用戶環境變量,交互,登陸才執行
- /etc/bashrc 用戶不能登陸,執行shell就生效
- ~/.bashrc
- ~/.bash_history
- ~/.bash_logout
- PS1='[\033[01;32m]\u@\h[\033[00m]:[\033[01;36m]\w[\033[00m]$ ' //帶顏色顯示命令行左邊
系統的環境變量配置文件
-
兩個緯度,一個是系統層次,一個是用戶層次shell
- 系統層次,就是/etc 下的文件
- 用戶層次,就是用戶家目錄下的文件。每一個用戶的家目錄下都會有以 . 點開頭的隱藏文件.bash_profile或 .bashrc
-
兩種類型,把 bashrc 做爲一種類型,把profile做爲一種類型bash
- 區別:
- profile是用戶登陸的時候,就會自動的加載profile,profile又會自動的調用bashrc
- bashrc是執行shell腳本的時候,用戶不用登陸,就能夠直接執行shell腳本,執行shell腳本就會調用bashrc裏面的一些配置 -系統中的 /etc/profile文件和 /etc/bashrc文件,通常不要去編輯它們
- 在遇到一些須要的時候,能夠編輯用戶家目錄下的.bash_profile
- source .bash_profile 或 . .bash_profile 加載配置文件中的配置
-
~/.bash_logout 文件,用來定義用戶退出的時候須要作的一些操做命令行
-
PS1是在/etc/bashrc中定義的code
- 在登陸一個系統以後,他會在命令左邊,有一串字符串 [root@hf-01 ~]
- 最左側是root,就是登錄用戶的名字
- @ 是主機名,hostname
- 而後是你所在的目錄最後一層級
[root@hf-01 ~]# echo $PS1
[\u@\h \W]\$
- 切換到/etc/sysconfig/network-scripts/,並將W改爲小寫w,會發現變成絕對路徑了
[root@hf-01 ~]# cd /etc/sysconfig/network-scripts/
[root@hf-01 network-scripts]# PS1='[\u@\h \w]\$'
[root@hf-01 /etc/sysconfig/network-scripts]#
[root@hf-01 ~]# cd 123/
[root@hf-01 ~/123]# cd /tmp/
[root@hf-01 /tmp]#
這是一個全局路徑
[root@hf-01 /tmp]# PS1='\u@\h \w\$'
root@hf-01 /tmp#
root@hf-01 /tmp# PS1='<\u@\h \w> \$'
<root@hf-01 /tmp> #
普通用戶是 $號,root用戶是# 號
PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;36m\]\w\[\033[00m\]\$ '