要修改Ubuntu12.04的终端命令行标题,首先要知道该显示样式是在哪里配置的,并且以哪些内容组织起来的。
修改终端命令行显示样式步骤:
1、打开~/.bashrc文件,如
sheleng@sheleng-ThinkPad-r61i:~$ vim /home/sheleng/.bashrc
.bashrc 这个文件主要保存个人的一些个性化设置,如命令别名、路径等。
2、定位到# If this is an xterm set the title to user@host:dir 具体如下:
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
3、由此可知终端命令行标题的组成形式是:user@host:dir,其中:
user:用户名,我的用户名是sheleng。
host:主机名,在安装Ubuntu12.04时默认是sheleng-ThinkPad-r61i(略长,此次就是要把它改了),ThinkPad-r61i是我的笔记本型号(古董机了)。
dir:当前所在的路径。
4、user和dir都没什么可改的了,我就想把这个host给改的短一点。
查看host方法(直接在终端中输入hostname即可):
hostname
修改host方法(需要修改两处,分别是:/etc/host 与 /etc/hosts):
sheleng@sheleng-ThinkPad-r61i:~$ sudo vim /etc/hostname
sheleng@sheleng-ThinkPad-r61i:~$ sudo vim /etc/hosts
我这里就把原先默认的sheleng-ThinkPad-r61i修改为r61i,然后保存并退出。
注意:必须保持/etc/hostname里的主机名与/etc/hosts里127.0.1.1 后的主机名相同,否则在终端sudo的时候会出现无法解析主机名情况。
5、重启(一定要重启)。
6、重新打开终端,命令行标题是不是已经短了许多。
sheleng@r61i:~$