Change the Linux Bash prompt

To change the Linux Bash prompt to a different format, simply set the PS1 variable

PS1="new prompt text"

There are several options that you can use to show different things

Switch Purpose
\u current User
\h short Hostname – up to the first “.”
\H full Hostname
\w current full path
\W current directory
\d the date in in “Weekday Month Date” format
\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

The most common is

PS1="\u@\h \W"

which gives the user name, hostname and current path.

To make this pernament, you need to add it to any one of the startup script files, the most common places are

  • /etc/profile
  • /etc/bashrc
  • ~/.bash_profile
  • ~/.bashrc

Leave a comment

Your email address will not be published. Required fields are marked *