bash登陆后显示的欢迎信息由/etc/issue,/etc/issue.net(远程登录)设定。 例如,文件内容为:
[root@iZwz9ayvrn26ptadymu9ymZ ~]# cat /etc/issue
\S
Kernel \r on an \m
那么登录时显示的信息为:
CentOS Linux7 (Core)
Kernel 3.10.0-693.5.2.el7.x86_64 on an x86_64
issue文件内可以设置的参数有:
代码 | 含义 |
---|---|
\d | 本地端时间的日期 |
\l | 显示第几个终端机接口 |
\m | 显示硬件等级 |
\n | 显示主机网络名称 |
\O | 显示domain name |
\r | 操作系统的版本(相当于 uname -r) |
\t | 显示本地端时间的时间 |
\S | 操作系统名称 |
\v | 操作系统的版本 |
登录后可以显示一些通知信息,在/etc/motd中设。
在login shell中,登陆后读取两个配置文件:
/etc/profile
:系统全局配置文件~/.bash_profile
或 ~/.bash_login
或 ~/.profile
:使用者个人配置文件全局配置文件,设定的变量主要有:
此外,改文件还会引入其他的数据。
for i in /etc/profile.d/*.sh ; do
if [ -r "$i" ]; then
if [ "${-#*i}" != "$-" ]; then
. "$i"
else
. "$i" >/dev/null
fi
fi
done
这些文件规范了bash操作接口的颜色,语系,ll,ls,vi,which等命令的别名。如果要在全局设定共享命令,可以再这个文件夹下面建立扩展名为.sh的文件。
bash读取/etc/profile并执行之后,会读取用户个人配置文件,按照如下顺序查找,并读取找到的第一个:
其文件内容为:
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
可以看到,文件对PATH变量进行了补充,还读取了bashrc文件
那么,login shell的配置文件读取流程为:
login shell配置文件读取流程
用户个人的配置信息存放在~/.bashrc中,其内容一般为:
# .bashrc
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
如果有修改,需要主要后重新登录才会生效。
或者用source
或者小数点(.)符号重新载入
srouce ~/.bashrc
. ~/.bashrc
可以看到~/.bashrc最后调用了/etc/bashrc
文件,这是CentOS特有的,其功能为:
/etc/profile.d/*.sh
的设定stty(setting tty)可以查看或者设定terminal的输入按键含义(另起笔记学习)。 查看当前stty参数:
[root@iZwz9ayvrn26ptadymu9ymZ ~]# stty -a
speed 38400 baud; rows 26; columns 69; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z;
rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl
ixon -ixoff -iuclc -ixany -imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0
bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop
-echoprt echoctl echoke
部分解释为:
设定参数的命令为:
stty [指令] [按键]
set可以显示所有的变量,可以设置输出指令输入/输出的环境(另起笔记学习),其格式为
set [-uvCHhmBx]