Find knowledge base article(s) by searching for keywords in the title e.g. type linux in the search box below
Find knowledge base article(s) by browsing the subject categories of articles
Technology quick references, cheatsheets, user manuals etc.
Shop Online through ShopifyLite
Tutorials on various IT applications.
Search Title    (UL:0 |SS:f)

Software >> OS >> Unix >> Shell >> How to set shell prompt string

Korn Shell (/bin/ksh)

vi .profile
add following line
PS1="$LOGNAME@`uname -n`$ " ; export PS1

Bash (/bin/bash)
# export PS1="promptstring"

\d : date in Weekday Month Date format
\h : hostname up to first "." i.e. hostname part in FQDN
\H : hostname i.e. FQDN 

 

Example Result
PS1="\d$ " Tue Sep 28$
PS1="\h$ " hostname$
PS1="\u@\h$ " user@hostname$

 

 

 

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 %~ %~
Full hostname 'uname -n' 'uname -n' N/A %M %M
Hostname up to the first '.' `hostname -s` `hostname -s` \h %m %m
Start (stop) boldfacing mode %B (or %b) N/A N/A %B (or %b) %B (or %b)
Start (stop) standout mode %S (or %s) N/A N/A %S (or %s) %S (or %s)
Start (stop) underline mode %U (or %u) 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 %l N/A N/A %| %|
The current history number %h 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 hh:mm AM/PM %t N/A \@ %t (or %@) %t (or %@)
Time of day in 24-hour hh:mm %T N/A \A %T %T
Time of day in 12-hour with seconds hh:mm:ss AM/PM %p N/A \T %p N/A
Time of day in 24-hour with seconds hh:mm:nn %P N/A \t %P %*
The day in 'dd' format %D N/A N/A %D N/A
The month in 'Mon' format %w N/A N/A %w N/A
The month in 'mm' format %W N/A N/A %W N/A
The year in 'yy' format %y N/A N/A %y N/A
The year in 'yyyy' format %Y 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 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 N/A N/A %D
The weekday in 'Day' format %d N/A N/A %d N/A
Description csh* ksh bash tcsh* zsh

References

[1] http://www.thegeekstuff.com/2008/09/bash-shell-ps1-10-examples-to-make-your-linux-prompt-like-angelina-jolie/

[ © 2008-2021 myfaqbase.com - A property of WPDC Consulting ]