Chinaunix首页 | 论坛 | 博客
  • 博客访问: 204890
  • 博文数量: 111
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 790
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-29 13:41
文章分类

全部博文(111)

文章存档

2018年(10)

2017年(27)

2016年(18)

2015年(31)

2014年(25)

分类: 系统运维

2015-04-01 16:00:08

bash里面的#这个提示符前的内容是可以修改的:
先看看操作系统版本
[jim@localhost /]$ lsb_release -a
LSB Version: :core-3.1-ia32:core-3.1-noarch:core-3.2-ia32:core-3.2-noarch:desktop-3.1-ia32:desktop-3.1-noarch:desktop-3.2-ia32:desktop-3.2-noarch
Distributor ID: Fedora
Description: Fedora release 10 (Cambridge)
Release: 10
Codename: Cambridge
[jim@localhost /]$

接下来看看bash中的PS1格式:
[jim@localhost /]$ set | grep PS1
PS1='[\u@\h \W]\$ '
[jim@localhost /]$

PS1是bash环境变量预设的值,各个参数的说明如下:

PROMPTING
When executing interactively, bash displays the primary prompt PS1 when
it is ready to read a command, and the secondary prompt PS2 when it
needs more input to complete a command. Bash allows these prompt
strings to be customized by inserting a number of backslash-escaped
special characters that are decoded as follows:
\a an ASCII bell character (07)
\d the date in "Weekday Month Date" format (e.g., "Tue May
26")
\D{format}
the format is passed to strftime(3) and the result is
inserted into the prompt string; an empty format results
in a locale-specific time representation. The braces are
required
\e an ASCII escape character (033)
\h the hostname up to the first ‘.’
\H the hostname
\j the number of jobs currently managed by the shell
\l the basename of the shell’s terminal device name
\n newline
\r carriage return
\s the name of the shell, the basename of $0 (the portion
following the final slash)
\t the current time in 24-hour HH:MM:SS format
\T the current time in 12-hour HH:MM:SS format
\@ the current time in 12-hour am/pm format
\A the current time in 24-hour HH:MM format
\u the username of the current user
\v the version of bash (e.g., 2.00)
\V the release of bash, version + patch level (e.g., 2.00.0)
\w the current working directory, with $HOME abbreviated
with a tilde
\W the basename of the current working directory, with $HOME
abbreviated with a tilde
\! the history number of this command
\# the command number of this command
\$ if the effective UID is 0, a #, otherwise a $
\nnn the character corresponding to the octal number nnn
\\ a backslash
\[ begin a sequence of non-printing characters, which could
be used to embed a terminal control sequence into the
prompt
\] end a sequence of non-printing characters
如果想把自己的PS1 修改为下面这样:
[jmi@localhost 00:21 #2]$
#2表示是在该bash中的第二次command
该怎么修改呢?
PS1='[\u@\h \A #\#]\$'

一般路径会在shell的顶端显示,所以路径信息不用显示在PS中。
localhost这种域名一般也用不到,也可以删掉。
其实我觉得嘛,所有的信息都可以去掉。因为root和普通用户也只是$和~的区别。
不过用户名还是需要的,可以作为区分。

所以最后的PS应该是:
PS1='[\u]\$'
阅读(368) | 评论(0) | 转发(0) |
0

上一篇:sed高级命令

下一篇:sed高级命令

给主人留下些什么吧!~~