环境变量配置文件目录概要
- /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\]\$ '