|
|
|
|
|
|
|
|
How do I change my system prompt?
|
|
"The prince wants your daughter for his wife."
"Well, tell him his wife can't have her."
- Blackadder III
Step 1 |
-
To edit/change your system prompt, you need to edit your
.*rc file in your home directory. Of course, the .*rc file
will be different depending on your current login shell.
I strongly recommend you to read some information on
the differences among login
shells before changing your system prompt.
You can find out your current login shell by typing
-
$ echo $SHELL
(yes, $SHELL in uppercase)
Shell found from "echo $SHELL" |
Description |
You need to edit this dot "rc" filein your home directory |
/usr/local/bin/bash |
Bourne again Shell, v1.14 |
.bashrc |
/usr/local/bin/bash202 |
Bourne again Shell, v2.02 |
.bashrc |
/usr/local/bin/tcsh |
Tc Shell |
.tcshrc (or .cshrc) |
/usr/local/bin/zsh |
Z Shell |
.zshrc |
/bin/csh |
C Shell |
.cshrc |
/bin/ksh |
Korn Shell |
.kshrc or .profile |
Step 2 |
-
Before doing anything, it is always a good idea to make a backup file
first. (so that you can go back safely) After making backup of your .*rc
file you found from Step 1 in your home
directory, open the .*rc file using your favorite text editor (vi,
emacs, pico, nedit, dtpad, etc.), and find a line starting with 'set
prompt=' (csh and tcsh) or 'PS1' (bash, zsh and ksh) depending on your
current login shell.
Table below lists most prompt variables that you can use to choose and match
in a given shell.
|
Prompt Variable Description |
|
csh |
ksh |
bash |
tcsh |
zsh |
|
|
Current working directory |
|
$CWD |
$PWD |
\w |
%/ |
%/ |
|
|
Current working directory, with one's home directory by `~' |
|
$CWD:t |
$PWD##*/ |
\W |
%c |
%~ |
|
|
Full hostname |
|
N/A |
N/A |
N/A |
%M |
%M |
|
|
Hostname up to the first '.' |
|
`hostname -s` |
`uname -n` |
\h |
%m |
%m |
|
|
Start (stop) boldfacing mode |
|
N/A |
N/A |
N/A |
%B (or %b) |
%B (or %b) |
|
|
Start (stop) standout mode |
|
N/A |
N/A |
| %S (or %s) |
%S (or %s) |
|
|
Start (stop) underline mode |
|
N/A |
N/A |
N/A |
%U (or %u) |
%U (or %u) |
|
|
User name |
|
`whoami` |
`logname` |
\u |
%n |
%n |
|
|
The shell's tty that the user is logged in on |
|
N/A |
N/A |
N/A |
%l |
%l |
|
|
The current history number |
|
N/A |
N/A |
\! |
%h (or %!) |
%h (or %!) |
|
|
Name of the shell |
|
N/A |
N/A |
\s |
N/A |
N/A |
|
|
Time of day in 12-hour AM/PM format |
|
N/A |
N/A |
| %t (or %@) |
%t (or %@) |
|
|
Time of day in 24-hour format |
|
N/A |
N/A |
N/A |
%T |
%T |
|
|
'Precise' time of day in 12-hour AM/PM format, with seconds |
|
N/A |
N/A |
| %p |
N/A |
|
|
'Precise' time of day in 24-hour format, with seconds |
|
N/A |
N/A |
\t |
%P |
%* |
|
|
The day in 'dd' format |
|
N/A |
N/A |
| %D |
N/A |
|
|
The month in 'Mon' format |
|
N/A |
N/A |
N/A |
%w |
N/A |
|
|
The month in 'mm' format |
|
N/A |
N/A |
| %W |
N/A |
|
|
The year in 'yy' format |
|
N/A |
N/A |
N/A |
%y |
N/A |
|
|
The year in 'yyyy' format |
|
N/A |
N/A |
| %Y |
N/A |
|
|
The date in "Weekday Month Date" format |
|
N/A |
N/A |
\d |
N/A |
N/A |
|
|
The date in day-dd format |
|
N/A |
N/A |
|
| %w |
|
|
The date in Mon/dd/yy format |
|
N/A |
N/A |
N/A |
N/A |
%W |
|
|
The date in yy-mm-dd format |
|
N/A |
N/A |
|
|
| |
|
The weekday in 'Day' format |
|
N/A |
N/A |
N/A |
%d |
N/A |
|
|
Prompt Variable Description |
|
csh |
ksh |
bash |
tcsh |
zsh |
|
N/A = Not Available or simply I don't know.
If you know the correct varaible(s), please
let me know, I'll update the table.
TIA.
O.k., Here are some examples for shell prompt manipulation;
Shell |
Prompt/PS1 setting in rc file |
Your prompt would look like |
csh |
set prompt="`whoami`@`hostname` $cwd ->" |
yoon@sycamore /usr/dt/include -> |
csh |
set prompt="$CWD:t% " |
src (i.e., CWD=/usr/local/X11/src) |
csh |
set prompt="%c1" |
TestDir (of /home/user/TestDir)
only print last directory name in the CWD path.
<Contributed by Ben Herfurth>
|
ksh |
export PS1=`logname`@`uname -n`:'$PWD' |
yoon@sonic:/home/gis/nsf |
bash |
export PS1="\u:\h [\d] " |
yoon:rhino [Tue May 26] |
bash |
export PS1="\s|\h \W] " |
bash|cedar ~\lib\OpenGL] |
tcsh |
set prompt="%B[%@]%b %n %B[%~]%b%h: " |
[12:30p] yoon [~/research]10: |
tcsh |
set prompt = "tcsh %B[%@]%b %m[%/] " |
tcsh [2:54pm] sparky[/usr/local/lib] |
tcsh |
set prompt = "tcsh: %d-%D/%W %B[%p]%b %/ > " |
tcsh: Fri-09/04 [8:22:38pm] /var/temp > |
zsh |
export PS1="%S zsh %s in %B%m%b [%W] %~ }" |
zsh in maple [2/15/05] ~/project
} |
zsh |
export PROMPT="%B%m%b %/ }" |
sequoia /home/yoon/research/FEM } |
Step 3 |
-
Once prompt definition is save in .*rc, new prompt setting will be in effect
next time you login. If you wish to make the prompt change in effect right away,
update your .*rc by sourcing it out.
For Bourne shell category (bash, zsh and ksh)
-
$ . .bashrc (bash)
$ . .zshrc (zsh)
$ . .kshrc (ksh)
For C shell category (csh and tcsh)
-
$ source .tcshrc (tcsh)
$ source .cshrc (csh)
|
|
|