• Home
  • Disclaimer
  • Contact
  • Archives
  • About
  • Subscribe
  • Support
  • Advertise

Kernel Talks

Unix, Linux, & Cloud!

  • How-to guides
    • Howto
    • Disk management
    • Configurations
    • Troubleshooting
  • OS
    • HPUX
    • Linux
  • Miscellaneous
    • Software & Tools
    • Cloud Services
    • System services
    • Virtualization
  • Certification Preparations
    • AWS Certified Solutions Architect – Associate
    • AWS Certified Solutions Architect – Professional
    • AWS Certified SysOps Administrator – Associate
    • AWS Certified Cloud Practitioner
    • Certified Kubernetes Administrator
    • Hashicorp Certified Terraform Associate
    • Oracle Cloud Infrastructure Foundations 2020 – Associate
  • Tips & Tricks
  • Linux commands
You are here: Home / System services

How to change your shell prompt to fancy one instantly

Published: January 4, 2017 | Modified: June 20, 2020



Learn to change shell prompt with your chosen character or value. Different values or shell variables can be defined to be shown as shell prompt.

After the user logged in to the system through Putty or command line he is greeted with blinking cursor in front of something called “Shell prompt”! Generally, the shell prompt with # denotes superuser and with $ denotes normal user. But going beyond these mainstream prompts, most of the admins choose the custom prompt for them and their users.

The most famous prompt used is showing the present working directory in prompt. So that users know in which directory he is while executing any command. Another widely used prompt is showing hostname. This ensures the user that he is working on the right terminal when many terminal windows are open. In this post, we will see how to set these prompts and some fancy prompts too.

Where to define Shell prompt :

Shell prompt is defined by PS1 variable in the profile file. This profile file can be any profile that is executed on user login. If multiple profiles have multiple values defined for PS1 then the last profile executed will decide the final value for PS1. For example when user logs in below profile execution can be followed :

/etc/profile -> ~/.bash_profile -> ~/.bashrc -> /etc/bashrc

In above flow system-wide profile i.e. /etc/profile calls bash profile which resides in the user’s home directory. This local profile calls bashrc script residing in the home directory. This bashrc calls up system-wide /etc/bashrc script to set the environment. In this case, PS1 value defined in /etc/bashrc would be the final one.

Sometimes there were no scripts called from profile then user’s home directory profile would be last resort to define PS1. If the profile file is missing in the user’s home directory the PS1 defined in /etc/profile will decide how your prompt looks.

How to define shell prompt :

Now, you know the file where prompt can be defined. Let’s see how to define it. It can be defined in a very basic way as below :

PS1=":->"
export $PS1

Here we are defining prompt as the symbol :-> The export command is not necessary but it’s good to have it in some flavors of Linux or Unix. Even you can test it by running command PS1=":->" on your terminal and you can see immediately your prompt will be changed to :->

You can even use an if-else loop in the profile file to decide which prompt should be served for particular users or terminal types.

Different useful prompts :

Below is the useful list of variables can be used in prompts :

Code
Description
PS1=”[$USER@$HOSTNAME]$” Shows prompt as [username@hostname]$
PS1=”[$USER@$HOSTNAME $PWD]$” Shows prompt as [username@hostname Present_directory]$
PS1=”[$HOSTNAME $PWD]$” Shows prompt as [hostname present_directory]$
PS1=”$HOSTNAME >” Shows prompt as hostname >

You can choose your own variations. See above-listed prompts in action below :

$PS1="[$USER@$HOSTNAME]$"
[user4@testsrv2]$

$PS1="[$USER@$HOSTNAME $PWD]$"
[user4@testsrv2 /home/user4]$

$PS1="[$HOSTNAME $PWD]$"
[testsrv2 /home/user4]$

$PS1="$HOSTNAME >"
testsrv2 >

Observe the first prompt is just $ sign. After each PS1 value change, prompt changes accordingly.

Some fancy prompts :

Here are some fancy prompts for fun!

$PS1=">-->"
>-->

$PS1="-=(^_^)=-:"
-=(^_^)=-:

$PS1="\m/ (-_-) \m/ :"
\m/ (-_-) \m/ :

$PS1="$USER rules $HOSTNAME >"
user4 rules testsrv2>

Hope you liked the post. Drop us your feedback, suggestions in comments below! Do follow us on Facebook, Twitter & Google+

⇠ Previous article
Step by step procedure to take ignite tape backup in HPUX
Next article ⇢
How to zip, unzip files and directories in Linux / Unix

Related stuff:

  • 5 steps guide for SMTP configuration in Linux
  • How to restart NFS in HPUX
  • Build Syslog server in Linux for centralized log management
  • How to do safe and graceful Measureware service restart in HPUX
  • What are the huge pages in Linux?
  • What is umask value? How to set it up?
  • Linux scheduler: Cron, At jobs
  • 4 steps guide for SMTP configuration in HPUX
  • 6 ways to manage service startups using chkconfig in Linux
  • How to configure JBOSS EAP 7 as a service in SUSE Linux
  • How to restart service in Linux

Filed Under: System services Tagged With: custom shell prompt, Display hostname in shell prompt, How to change shell prompt, How to define shell prompt, How to export PS1, PS1 in profile, Show hostname in shell prompt, Show present working directory in shell prompt

If you like my tutorials and if they helped you in any way, then

  • Consider buying me a cup of coffee via paypal!
  • Subscribe to our newsletter here!
  • Like KernelTalks Facebook page.
  • Follow us on Twitter.
  • Add our RSS feed to your feed reader.

Share Your Comments & Feedback: Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get fresh content from KernelTalks

  • Email
  • Facebook
  • RSS
  • Twitter

Get Linux & Unix stuff right into your mailbox. Subscribe now!

* indicates required

This work is licensed under a CC-BY-NC license · Privacy Policy
© Copyright 2016-2023 KernelTalks · All Rights Reserved.
The content is copyrighted to Shrikant Lavhate & can not be reproduced either online or offline without prior permission.