原本使用公司自己的服务器的时候,命令行提示符不是什么问题,一个是主机名称都被设置好了,另一个是即使没有被设置也不是很长。但是自己开始用EC2之后发现它的命令行提示符实在是太长了, 比如:
ec2-user@ip-10-2-215-206 ~]$
由于将来肯定会管理多个instance, 所以就决定做一个并不困难但是早就应该做的事情,更改命令行提示符。
方法有很多,有些需要重启主机,那还是算了, EC2重启以后IP什么的还得重新设置。由于只有我一个人用命令行,所以就不用那种针对用户的修改。
先是
sudo sh -c 'echo "export NICKNAME=ChipChaServer" > /etc/profile.d/prompt.sh'
然后
sudo emacs /etc/nashrc
我知道很多人习惯使用VI, 怎奈何我是在记不得组合键,就用相对熟悉的emacs
进去以后用ctrl+S找到shopt那块
# Turn on checkwinsize
shopt -s checkwinsize
[ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ " <------ 将此处的\h改为$NICKNAME, 参看下一代码块
# You might want to have e.g. tty in prompt (e.g. more virtual machines)
# and console windows
# If you want to do so, just add e.g.
# if [ "$PS1" ]; then
# PS1="[\u@\h:\l \W]\\$ "
# fi
# Turn on checkwinsize
shopt -s checkwinsize
[ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@$NICKNAME \W]\\$ "
# You might want to have e.g. tty in prompt (e.g. more virtual machines)
# and console windows
# If you want to do so, just add e.g.
# if [ "$PS1" ]; then
# PS1="[\u@\h:\l \W]\\$ "
# fi
然后再开一个terminal的时候,提示符就变了,如下:
[ec2-user@ChipChaServer ~]$
搞定