Home
Open Source
Technology
Linux
Linux Basics
Linux Distributions
Arch Linux
CentOS
Debian
Fedora
Linux Mint
Mageia
Mandrake
Mandriva
openSUSE
Red Hat Enterprise Linux
Scienti�c Linux
Unix
FreeBSD
Free Videos and EBooks
Donate
Backup tools
Cloud
Database
Directory servers
Mobile
Android
Reviews
Security
Encryption / Decryption
Monitoring Tools
Tips and Tricks
Internet hacks
Trouble shooting
Virtualization
BASH /
FAQ /
LINUX /
LINUX
BASICS /
TIPS AND
TRICKS
How To
Customize
Bash
Prompt In
Linux
BY SK ·
PUBLISHED
NOVEMBER
19, 2018 ·
UPDATED
JANUARY 17,
2020
As SHARE
you
know
already,
BASH
(the
Bourne-
Again
Shell)
is
the
default
shell
for
most
modern
Linux
distributions.
In
this
guide,
we
are
going
to
customize
BASH
prompt
and
enhance
its
look
by
adding
some
colors
and
styles.
Of
course,
there
are
many
plugins/tools
available
to
get
this
job
done
easily
and
quickly.
However,
we
still
can
do
some
basic
customization,
such
as
adding,
modifying
elements,
changing
the
foreground
and
background
color
etc.,
without
having
to
install
any
additional
tools
and
plugins.
C
u
s
t
o
m
i
z
e
B
a
s
h
P
r
o
m
p
t
I
n
L
i
n
u
x
In
BASH,
we
can
customize
and
change
the
BASH
prompt
as
the
way
you
want
by
changing
the
value
of
PS1
environment
variable.
Usually,
the
BASH
prompt
will
look
something
like
below:
BASH
prompt
in
Ubuntu
Here,
sk
is
username
and
ubuntuserver
is
hostname.
Now,
we
are
going
to
change
this
prompt
as
per
our
liking
by
inserting
some
backslash-
escaped
special
characters
called
Escape
Sequences.
Let
me
show
you
some
examples.
Before
going
further,
it
is
highly
recommended
to
backup
the
~/.bashrc
�le.
$ cp ~/.bashrc ~/.b
M
o
d
i
f
y
“
u
s
e
r
n
a
m
e
@
h
o
s
t
n
a
m
e
”
p
a
r
t
i
n
t
h
e
B
a
s
h
p
r
o
m
p
t
As
I
mentioned
above,
the
BASH
prompt
has
“username@hostname”
part
by
default
in
most
Linux
distributions.
You
can
change
this
part
to
something
else.
To
do
so,
edit ~/.bashrc �le:
$ vi ~/.bashrc
Add
the
following
line
at
the
end:
PS1="ostechnix> "
Replace
“ostechnix”
with
any
letters/words
of
your
choice.
Once
added,
hit
the
ESC
key
and
type
:wq
to
save
and
exit
the
�le.
Run
the
following
command
to
update
the
changes:
$ source ~/.bashrc
Now,
the
BASH
prompt
will
have
the
letters
“ostechnix”
in
the
shell
prompt.
Here
is
another
example.
I
am
going
to
replace
“username@hostname”
part
with
“Hello@welcome>”.
To
do
so,
add
the
following
entry
in
your
~./bashrc
�le.
export PS1="
Don’t
forget
to
update
the
changes
using
“source
~./bashrc”
command.
Here
is
the
output
of
my
BASH
prompt
in
Ubuntu
18.04
LTS.
Change
BASH
prompt
D
i
s
p
l
a
y
u
s
e
r
n
a
m
e
o
n
l
y
To
display
the
username
only,
just
add
the
following
line
in
~/.bashrc
�le.
export PS1="\u "
Here,
\u
is
the
escape
sequence.
Here
are
some
more
values
to
add
to
your
PS1
variable
to
change
the
BASH
prompt.
After
adding
each
entry,
you
must
run
“source
~/.bashrc”
command
to
take
e�ect
the
changes.
A
d
d
u
s
e
r
n
a
m
e
w
i
t
h
h
o
s
t
n
a
m
e
export PS1="\u\h "
Your
prompt
will
now
look
like
below:
skubuntuserver
A
d
d
u
s
e
r
n
a
m
e
a
n
d
F
Q
D
N
(
F
u
l
l
y
Q
u
a
l
i
f
i
e
d
D
o
m
a
i
n
N
a
m
e
)
export PS1="\u\H "
A
d
d
e
x
t
r
a
c
h
a
r
a
c
t
e
r
s
b
e
t
w
e
e
n
u
s
e
r
n
a
m
e
a
n
d
h
o
s
t
n
a
m
e
If
you
want
to
any
letter,
for
example
@,
between
the
username
and
hostname,
use
the
following
entry:
export PS1="\
The
bash
prompt
will
look
like
below:
sk@ubuntuserver
A
d
d
u
s
e
r
n
a
m
e
w
i
t
h
h
o
s
t
n
a
m
e
w
i
t
h
$
s
y
m
b
o
l
a
t
t
h
e
e
n
d
export PS1="\
A
d
d
s
p
e
c
i
a
l
c
h
a
r
a
c
t
e
r
s
b
e
t
w
e
e
n
a
n
d
a
f
t
e
r
u
s
e
r
n
a
m
e
a
n
d
h
o
s
t
n
a
m
e
export PS1="\
This
entry
will
change
the
BASH
prompt
as
shown
below.
sk@ubuntuserver
Similarly,
you
can
add
other
special
characters,
such
as
colon,
semi-
colon,
*,
underscore,
space
etc.
D
i
s
p
l
a
y
u
s
e
r
n
a
m
e
,
h
o
s
t
n
a
m
e
,
s
h
e
l
l
n
a
m
e
export PS1="\
D
i
s
p
l
a
y
u
s
e
r
n
a
m
e
,
h
o
s
t
n
a
m
e
,
s
h
e
l
l
a
n
d
a
n
d
i
t
s
v
e
r
s
i
o
n
export PS1="\
Bash
prompt
output:
Display
username,
hostname
and
path
to
current
directory:
export PS1="\
You
will
see
a
tilde
(~)
symbol
if
the
current
directory
is
$HOME.
D
i
s
p
l
a
y
d
a
t
e
i
n
B
A
S
H
p
r
o
m
p
t
To
display
date
with
your
username
and
hostname
in
the
BASH
prompt,
add
the
following
entry
in
~/.bashrc
�le.
export PS1="\
D
a
t
e
a
n
d
t
i
m
e
i
n
1
2
h
o
u
r
f
o
r
m
a
t
i
n
B
A
S
H
p
r
o
m
p
t
export PS1="\
D
a
t
e
a
n
d
1
2
h
o
u
r
t
i
m
e
h
h
:
m
m
:
s
s
f
o
r
m
a
t
export PS1="\
D
a
t
e
a
n
d
2
4
h
o
u
r
t
i
m
e
export PS1="\
D
a
t
e
a
n
d
2
4
h
o
u
r
h
h
:
m
m
:
s
s
f
o
r
m
a
t
export PS1="\
These
are
some
common
escape
sequences
to
change
the
Bash
prompt
format.
There
are
few
more
escape
sequences
are
available.
You
can
view
them
all
in
in
the
bash
man
page
under
the
“PROMPTING”
section.
And,
you
can
view
the
current
prompt
settings
at
any
time
using
command:
$ echo $PS1
H
i
d
e
“
u
s
e
r
n
a
m
e
@
h
o
s
t
n
a
m
e
”
P
a
r
t
I
n
B
a
s
h
p
r
o
m
p
t
I
don’t
want
to
change
anything.
Can
I
hide
it
altogether?
Yes,
you
can!
If
you’re
a
blogger
or
tech
writer,
there
are
chances
that
you
have
to
upload
the
screenshots
of
your
Linux
Terminal
in
your
websites
and
blogs.
Your
username/hostname
might
be
too
cool,
so
you
may
not
want
others
to
copy
and
use
them
as
their
own.
On
the
other
hand,
your
username/hostname
might
be
too
weird
or
too
bad
or
contain
o�ensive
characters,
so
you
don’t
want
others
to
view
them.
In
such
cases,
this
small
tip
might
help
you
to
hide
or
modify
“username@hostname”
part
in
Terminal.
If
you
don’t
like
to
let
the
users
to
view
your
username/hostname
part,
just
follow
the
steps
given
below.
Edit
your
“~/.bashrc”
�le:
$ vi ~/.bashrc
Add
the
following
at
the
end:
PS1="\W> "
Type
:wq
to
save
and
close
the
�le.
Then,
run
the
following
command
to
take
e�ect
the
changes.
$ source ~/.bashrc
That’s
it.
Now,
check
your
Terminal.
You
will
not
see
the
username@localhost
part.
You
will
only
see
the
~>
symbol.
Want
to
know
another
simplest
way
without
messing
the
~/.bashrc
�le?
Just
create
another
user
account
something
like
user@example,
or
admin@demo.
Use
these
accounts
for
making
guides,
videos
and
upload
them
on
your
blog
or
online.
Now,
you
have
nothing
to
worry
about
your
identity.
Warning:
This
is
a
bad
practice
in
some
cases.
For
example,
if
another
shells
like
zsh
inherits
your
current
shell,
it
will
cause
some
problems.
Use
it
only
for
hiding
or
modifying
your
username@localhost
part
if
you
use
single
shell.
Apart
from
hiding
the
username@localhost
part
in
the
Terminal,
this
tip
is
pretty
useless
and
might
be
problematic.
C
o
l
o
r
i
z
i
n
g
B
A
S
H
p
r
o
m
p
t
What
we
have
seen
so
far
is
we
just
changed/added
some
elements
to
the
BASH
prompt.
In
this
section,
we
are
going
to
add
colors
the
elements.
You
can
enhance
the
foreground
(text)
and
background
color
of
BASH
prompt’s
elements
by
adding
some
code
to
the
~/.bashrc
�le.
For
example,
to
change
the
foreground
color
of
all
texts
to
Red,
add
the
following
code:
export PS1="\
Once
added,
update
the
changes
using
command:
Now,
your
BASH
prompt
will
look
like
below:
Similarly,
to
change
the
background
color,
add
this
code:
export PS1="\
A
d
d
i
n
g
E
m
o
j
i
s
Who
doesn’t
love
emoji?
We
can
add
an
emoji
by
placing
the
following
code
in
the
~/.bashrc
�le.
PS1="\W
Please
note
that
some
terminal
may
not
show
the
emojis
properly
depending
upon
the
font
used.
You
may
see
either
garbled
characters
or
monochrome
emoji
if
you
don’t
have
suitable
fonts.
C
u
s
t
o
m
i
z
i
n
g
B
A
S
H
i
s
b
i
t
d
i
f
f
i
c
u
l
t
t
o
m
e
,
I
s
t
h
e
r
e
a
n
y
o
t
h
e
r
e
a
s
y
w
a
y
?
If
you’re
a
newbie,
writing
and
adding
PS1
values
will
be
confusing
and
di�cult.
Also,
you
will
�nd
it
bit
di�cult
to
arrange
the
elements
to
get
the
result
of
your
choice.
No
worries!
There
is
an
online
Bash
PS1
generator
available
which
allows
you
to
easily
generate
di�erent
PS1
values
as
you
wish.
Go
to
the
following
website:
Just
pick
the
elements
you
want
to
use
in
your
BASH
prompt.
Add
the
colors
to
the
elements
and
re-
arrange
them
in
any
order
of
your
liking.
Preview
the
output
instantly
and
�nally
copy/paste
resulting
code
in
your
~/.bashrc
�le.
It
is
that
simple!
Most
of
the
examples
mentioned
in
this
guide
are
taken
from
this
website.
Suggested
read:
How
To
Change
The
Sudo
Prompt
In
Linux
I
m
e
s
s
e
d
u
p
w
i
t
h
m
y
.
b
a
s
h
r
c
f
i
l
e
?
H
o
w
t
o
r
e
s
t
o
r
e
i
t
t
o
d
e
f
a
u
l
t
s
e
t
t
i
n
g
s
?
As
I
mentioned
earlier,
it
is
strongly
recommended
to
take
backup
~./bashrc
(Or
any
important
con�guration
�les
in
general)
before
making
any
changes.
So,
you
can
restore
it
to
the
previous
working
version
if
something
went
wrong.
However
if
you
forgot
to
backup
the
~/.bashrc
�le
in
the
�rst
place,
you
still
can
restore
it
to
the
default
settings
as
described
in
the
following
guide.
How
To
Restore
.bashrc
File
To
Default
Settings
The
above
guide
is
based
on
Ubuntu,
but
it
may
applicable
to
other
Linux
distributions
as
well.
Please
let
us
be
clear
that
the
aforementioned
guide
will
help
you
to
reset
~/.bashrc
to
its
default
settings
at
the
time
of
new
installation.
Any
changes
done
afterwards
will
be
lost.
Resource:
Bash
Reference
Manual
Thanks
for
stopping
by!
H
e
l
p
u
s
t
o
h
e
l
p
y
o
u
:
Subscribe
to
our
Email
Newsletter
:
Sign
Up
Now
Support
OSTechNix
:
Donate
Via
PayPal
Download
free
E-Books
and
Videos
:
OSTechNix
on
TradePub
Connect
with
us:
Reddit
|
Facebook
|
Twitter
|
LinkedIn
|
RSS
feeds
Have
a
Good
day!!
Share
this:
Reddit
Twitter
Facebook
LinkedIn
Pocket
WhatsApp
Telegram
Email
Print
Tags: BASH
CLI Linux
Modify
"username@localhost:"
Part
Shell
PREVIOUS
NEXT
STORY
STORY
ProtectedText
How
– To
A Change
Free GDM
Encrypted
Login
Notepad
Screen
To Background
Save In
Your Ubuntu
Notes
Online
3
RESPONS
ES
Comments 3
Pingbacks 0
ari
November
21, 2018
at 6:33
pm
Thank
you. I
allways
wanted
to add
the
time to
my
prompt
Reply
Anderson
Souza
August
7, 2019
at 9:21
pm
Great
article
man!
Reply
Johnny
Schmittou
October
21,
2019 at
10:05
pm
Awesome
article!
Well
done!!
Reply
LEAVE A
REPLY
Comment
Name
Email
* *
Website
Post Comment
This site
uses
Akismet to
reduce
spam. Learn
how your
comment
data is
processed.
EMAIL NEWSLETTER BLOG ARCHIVE WHO WE ARE
Select Month About
Subscribe to
our mailing list Contact Us
Donate
Sign Up Now
Privacy Policy
We respect
your privacy Terms and
Conditions
OSTechNix © 2020. All Rights
Reserved.
This site is licensed under CC BY-NC
4.0.