How to Change / Set up bash custom prompt (PS1) in Linux

So how do you setup, change and pimp out Linux / UNIX shell prompt? Most of us work with a shell prompt. By default most Linux distro displays hostname and current working directory. You can easily customize your prompt to display information important to you. You change look and feel by adding colors. In this small howto I will explain howto setup:

  1. How to customizing a bash shell to get a good looking prompt
  2. Configure the appearance of the terminal
  3. Apply themes using bashish
  4. How to pimp out your shell prompt

How To Customize Bash Prompt In Linux

Prompt is control via a special shell variable. You need to set PS1, PS2, PS3 and PS4 variable. If set, the value is executed as a command prior to issuing each primary prompt.

  • PS1 – The value of this parameter is expanded (see PROMPTING below) and used as the primary prompt string. The default value is \s-\v\$ .
  • PS2 – The value of this parameter is expanded as with PS1 and used as the secondary prompt string. The default is >
  • PS3 – The value of this parameter is used as the prompt for the select command
  • PS4 – The value of this parameter is expanded as with PS1 and the value is printed before each command bash displays during an execution trace. The first character of PS4 is replicated multiple times, as necessary, to indicate multiple levels of indirection. The default is +

How do I display current bash shell prompt setting?

Simply use the echo command, enter:
$ echo $PS1
Sample output:

[\u@\h \W]\$

How do I modify or change the prompt?

Modifying the prompt is easy task. Just assign a new value to PS1 and hit enter key:
My old prompt –> [vivek@105r2 ~]$
PS1="touch me : "
Sample outputs:

touch me : 

So when executing interactively, bash displays the primary prompt PS1 when it is ready to read a command, and the secondary prompt PS2 when it needs more input to complete a command. Bash allows these prompt strings to be customized by inserting a number of backslash-escaped special characters that are decoded as follows:

  • \a : an ASCII bell character (07)
  • \d : the date in “Weekday Month Date” format (e.g., “Tue May 26”)
  • \D{format} : the format is passed to strftime(3) and the result is inserted into the prompt string; an empty format results in a locale-specific time representation. The braces are required
  • \e : an ASCII escape character (033)
  • \h : the hostname up to the first ‘.’
  • \H : the hostname
  • \j : the number of jobs currently managed by the shell
  • \l : the basename of the shell’s terminal device name
  • \n : newline
  • \r : carriage return
  • \s : the name of the shell, the basename of $0 (the portion following the final slash)
  • \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
  • \A : the current time in 24-hour HH:MM format
  • \u : the username of the current user
  • \v : the version of bash (e.g., 2.00)
  • \V : the release of bash, version + patch level (e.g., 2.00.0)
  • \w : the current working directory, with $HOME abbreviated with a tilde
  • \W : the basename of the current working directory, with $HOME abbreviated with a tilde
  • \! : the history number of this command
  • \# : the command number of this command
  • \$ : if the effective UID is 0, a #, otherwise a $
  • \nnn : the character corresponding to the octal number nnn
  • \\ : a backslash
  • \[ : begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt
  • \] : end a sequence of non-printing characters


Let us try to set the prompt so that it can display today’s date and hostname:
PS1="\d \h $ "
Sample output:

Sat Jun 02 server $ 

Now setup prompt to display date/time, hostname and the current working directory:
PS1="[\d \t \u@\h:\w ] $ "
Sample utputs:

[Sat Jun 02 14:24:12 vivek@server:~ ] $

How do I add colors to my prompt?

You can change the color of your shell prompt to impress your friend or to make your own life quite easy while working at command prompt.

Putting it all together

Let us say when you login as root/superuser, you want to get visual confirmation using red color prompt. To distinguish between superuser and normal user you use last character in the prompt, if it changes from $ to #, you have superuser privileges. So let us set your prompt color to RED when you login as root, otherwise display normal prompt.

Open /etc/bashrc (Redhat and friends) / or /etc/bash.bashrc (Debian/Ubuntu) or /etc/bash.bashrc.local (Suse and others) file and append following code:
# vi /etc/bashrc
$ sudo gedit /etc/bashrc
Append the code as follows

# If id command returns zero, you got root access.
if [ $(id -u) -eq 0 ];
then # you are root, set red colour prompt
  PS1="\\[$(tput setaf 1)\\]\\u@\\h:\\w #\\[$(tput sgr0)\\]"
else # normal
  PS1="[\\u@\\h:\\w] $"

Close and save the file.

My firepower prompt

Check this out:

(click to enlarge)

You can also create complex themes for your bash shell using bashish. Bashish is a theme enviroment for text terminals. It can change colors, font, transparency and background image on a per-application basis. Additionally Bashish supports prompt changing on common shells such as bash, zsh and tcsh. Install bashish using rpm or apt-get command:
# rpm -ivh bashish*
# dpkg -i bashish*
Now start bashish for installing user configuration files:
$ bashish
Next you must restart your shell by typing the following command:
$ exec bash
To configure the Bashish theme engine, run
$ bashishtheme

basish in action (screenshots from official site):

Finally, you can always use aterm or other terminal program such as rxvt. It supports nice visual effect , like transparency, tinting and much more by visiting profile menu. Select your terminal > click on Edit menu bar > Profiles > Select Profile > Click on Edit button > Select Effects tab > Select transparent background > Close

(click to enlarge)

How to celebrate the holidays at your bash prompt

Most modern Linux terminal supports Unicode. So you can add the following emojis:

Emoji Description
🎄 Christmas Tree
🦌 Deer
🤶 Mrs. Claus
🎅 Santa Claus
🧣 Scarf
🎁 Wrapped Gift

Let us add colors and Christmas tree/Santa to our PS1:

export PS1="🎅\[\e[33;41m\][\[\e[m\]\[\e[32m\]\u\[\e[m\]\[\e[36m\]@\[\e[m\]\[\e[34m\]\h\[\e[m\]\[\e[33;41m\]]\[\e[m\]🎄 "


See the following urls for more info:

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 106 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
106 comments… add one
  • akashdeep Jun 3, 2007 @ 9:12

    LOL .. nice your command is my wish

    • Mike Jul 21, 2011 @ 20:47

      Since I’m not a bash-geek it took me several days to … understand how that all works but I’ve figured it out at last and so I played around and this is my PS1 for now:

      PS1=”n[e[0;36m]┌─[[e[0m][e[1;33m]u[e[0m][e[1;36m] @ [e[0m][e[1;33m]h[e[0m][e[0;36m]]─[[e[0m][e[1;34m]w[e[0m][e[0;36m]][e[0;36m]─[[e[0m][e[0;31m]![e[0m][e[0;36m]][e[0m]n[e[0;36m]└─[[e[0m][e[1;37m]$[e[0m][e[0;36m]]› [e[0m]”

      How do you like this one?

      • Name Nov 6, 2013 @ 12:41


      • jack Jan 29, 2014 @ 12:03

        You are one of those american morons who know nothing about linux

        • Cody Jan 31, 2014 @ 0:35

          This is to Jack, in case it isn’t obvious.

          Typically those who have nothing constructive to say (i.e., no suggestions for improvement, nothing of real value) and only write insulting statements (e.g., “You are one of those american[1] morons who know nothing about linux[2]”) are those who know the least of all. How do I know this? It’s simple: you only can insult, which is akin to being a bully. And what do bullies do? They have serious self esteem problems and to the point that they are so down on themselves that they only feel better by (trying; somehow I gather you failed miserably here) to take others down to [your] level. If you want to go to your post though, here’s a thought:
          This article is not about Linux. In fact, Linux is by itself a kernel – just the core of an operating system – whereas this is a thread about a shell that can work on Linux based operating systems and non Linux based operating systems (the shell could be seen as an interface between the kernel and the user). So to put it into perspective, you must be one of those “morons” who has little to no reading comprehension. Right? I mean that’s what you’re showing.

          Get a life or at least provide something constructive, rather than showing that you are exactly what you are claiming someone else is (By the way, the very fact you think knowing nothing about Linux somehow equates to being a moron, shows you are very naive, at best, about this world – indeed, if it were not for the fact that humans have different skill sets and different strengths and weaknesses, we’d all be extinct decades if not centuries ago).

          [1]American, not american.
          [2] Did you forget your period to end the sentence?
          Obviously I’m being deliberately arrogant with these two points. Why would I do that? To make a point. No one is perfect and it doesn’t really matter if you’re writing professionally, formal or informally when responding to a blog, but since all you can do is insult (providing nothing else) then well, fair is fair.

          • Brandon Feb 14, 2014 @ 20:58

            This made my day, and I couldn’t have said it better myself.

            • Cody Feb 16, 2014 @ 3:00

              I’m glad. The funny thing is I think (and have beliefs and opinions) much more like Europeans (though see below) and so the reason I went after his remarks is not because I felt insulted but rather I find his remarks, well, as I already stated, naive and immature (and I cannot stand such traits). It was pure arrogance and beyond ignorant. Besides, let us all be real: if it were not for those “american morons” we’d not really have the Internet, would we? Further, even if we had the Internet, we cannot forget the fact that Unix was one of the first network operating systems and to this day is a huge part of the infrastructure in place. And of course, as I’m sure you know, what allowed Unix to be so successful (C is portable) is also because of Americans. Hell, AT&T is where Bell Labs was (not 100% sure where it is now) and what does AT&T mean again? Right, American Telephone and Telegraph, and both C and Unix were developed there. So, it was my pleasure to slam that insignificant in to the water in the way I did (I wish more stood up for me when I was bullied in school [for being so “different”] so many years ago and I think that is one of the reasons I make the effort to stand up for those who are being treated unfairly, where I can, and also call out others for their crap when necessary). In this case, there was simply nothing of value from his post (which is unhelpful and when combining it with trying to insult it is incredibly low) and while I highly suspect he won’t ever see it it still isn’t something I would let go without remarking on.

              Cheers, and thanks for the (admittedly, some what inferred) kind words (and if it indeed made your day I’m glad I wrote it more so).

          • James Feb 20, 2014 @ 20:40

            Agreed. An ad hominem is clear evidence of a lack of anything constructive or intelligent to say in the alternative.

            • Cody Mar 1, 2014 @ 17:12

              Thanks James. Glad you agree and thanks for the support as well. Although I already implied this to anyone who can see that Jack was just an … (use your imagination and note I love word play), if it were not for Unix the Linux kernel would not exist. And since Unix exists because of those “american morons”, well, who knows what Jack was thinking? He certainly wasn’t thinking of anything intelligible or constructive, as you pointed out.

          • Andrew Feb 5, 2015 @ 15:36

            I couldn’t have said it better. People that simply comment to be mean are absolutely obnoxious. And you are right – it is coming from a place of absolute insecurity. Thank you for taking the time to correct his actions.

            • Cody Feb 11, 2015 @ 14:52

              Thanks Andrew. Yes it is insecurity or otherwise self-esteem (lack thereof the latter). Besides his message was completely unintelligible (eligible yes but nothing intelligent at all). Indeed, a five year old (and that is probably too old still) could write something more intelligent (and clear). Even if they don’t know enough of (their) language (which is possible) to write (or type) it, they certainly could express it in words/body language/whatever else.

              As for correcting his actions. I wish. I can only call him out but unfortunately his mentality (exaggerated as it might be) is as I put it – a bully. Bullies rarely learn and they really cause problems for others, including – sadly – life long problems (even if there’s other variables, often the bullying is done because of the variables and that is besides the point). In short, though, I not only felt it appropriate to call him out, I felt it was needed and that is why I did it. Thanks for the comment.


              • john Apr 9, 2016 @ 20:11

                Wow. All this time and conversation about someone’s comment, who had a right to comment their opinion just as much as you lot. Have any of you been laid recently?

          • Ernst Feb 17, 2017 @ 11:56

            Cody, you are a pathetic lamer.

        • forza Jun 9, 2017 @ 15:53

          This comment made my day.

      • Divine_Bug Aug 13, 2015 @ 16:45

        It is awesome!!!

    • Bradley Feb 4, 2015 @ 0:38

      Very Interesting… The use of colours and theatre-style complex terminals is good, but one question… How did you get the PS1 variable to print out the command history number?

      • Robe Nov 23, 2015 @ 10:24

        If you see in the middle of the third line there is a “!”, this is the reference to the command history number. To my knowledge (which is very limited) this works in Bash and Kornshell, but I don’t know about any others.

        Hope that helps 🙂

  • Kirk Strauser Jun 13, 2007 @ 13:01

    Here’s my ZSH prompt. I start by defining a bunch of complicated variables, then actually build the prompt with a much more legible set of instructions.

    # Define common and useful things to put in a prompt
    typeset -A prc

    The result is like:

    kirk@mysystem [7:54} ~
    :) $

    where "kirk@mysystem" is green for normal users and red for root. The time is blue. The current directory is in red, and if it's longer that a set amount, the beginning is replaced with " ... " (so that you always see bottommost directory you're in). The smiley face is ":)" in green if the last command you typed executed correctly, or ":(" in red if it didn't. "$" is black, and if you're root, it's "#" instead.

    It packs a lot of useful information into a small area, like who you are, where you are, whether you're root, and whether you can make commands that succeed. If I see too many red frowns, I call it quits for the day.

    I think you can do most of this in Bash, too, but I never got that creative.

  • SimpleSimon Nov 27, 2007 @ 2:47

    Two things that I’d like to know how to do (if possible) with my bash prompt…

    1) Include the full path of the current directory, but only the last 25 characters if the path is longer than that. I’d also prefer a shortened path to be preceeded by “…”.

    2) Memorize the current cursor position, drop to the bottom line of the screen, output my prompt info, jump back to the previous cursor position.

    Either of these possible?

    • tlhonmey Mar 26, 2015 @ 22:51

      1) Yes. You can have the prompt execute fairly arbitrary things like so: PS1=’`pwd`’ This will make it run pwd every time it displays the prompt. Substitute a program or script that formats the output to your liking.

      2) Not so much. At least, not easily. You might look at Byobu. It can do things at the terminal level rather than the Bash level.

  • chika Jan 24, 2008 @ 15:51

    how to eliminate the hostname on the konsole?
    what should i add?

  • chika Jan 26, 2008 @ 17:42

    hey chika do this on your console

    PS1=”d $”

  • oscar Apr 17, 2008 @ 20:51

    How to change the prompt when access is via ssh, I have tried and don’t find that setting.

  • Jamie Apr 23, 2008 @ 0:24

    @ SimpleSimon

    For your first question, you want to look at the PROMPT_COMMAND variable. I don’t have an answer for your second question.

    # This will limit the path to 30 characters.
    PROMPT_COMMAND=’if [ ${#PWD} -gt 30 ]; then myPWD=${PWD:0:12}…${PWD:${#PWD}-15}; else myPWD=$PWD; fi’
    PS1=”u@h $myPWD$ ”


  • Reddy Sep 2, 2008 @ 10:12

    Thank you very much

  • Steve Nov 6, 2008 @ 16:20

    On slackware, I simply want:

    /home/steve $

    unless I su to root, then I want

    /home/steve #

    It would seem that this should do it:

    if [ $(id -u) -eq 0 ];
    then # you are root
    PS1=”$PWD #”
    else # normal
    PS1=”$PWD $”

    but after suing to root I still get

    /home/steve $

    How would I fix this?

    • felipe1982 Sep 7, 2011 @ 4:38

      > On slackware, I simply want:
      > /home/steve $
      > I su to root, then I want
      > /home/steve #

      put this into your ~/.bashrc
      export PS1=”w \$ ” #note doublebackslash$
      —- test —-
      [user@redhat5 ~]$ export PS1=”w \$ ”
      ~ $ su
      ~ #

  • Dan Nov 25, 2008 @ 22:07

    Steve, you may need to create .shrc file or whichever you’re using under root’s home directory so it gets sourced when you log in or sudo as root.

  • Balaji Nov 27, 2008 @ 20:15


    how to accept the prompt value into a variable.

    x=echo $PS1 : this is not working


  • 🐧 nixCraft Nov 27, 2008 @ 20:20


    Use following code

    x=$(echo $PS1)
    echo $x
  • Balaji Nov 27, 2008 @ 20:31

    Hi Vivek,

    i still get an error.

    bash-2.05b$ promt.ksh
    ./promt.ksh[7]: syntax error: `1′ unexpected

    bash-2.05b$ cat promt.ksh

    x=$(echo $PS1)

    echo $x

    exit (1)

    • Jan Jan 17, 2012 @ 11:14

      try x=`echo $PS1`

      • 🐧 nixCraft Jan 17, 2012 @ 11:27

        To assign an variable use the following syntax. No need to echo it:

        echo "x is $x"
  • Bret Sutton Nov 30, 2008 @ 9:46

    As the error message says, the error is on line 7, which appears to be your exit command. If you want to exit with a non-zero return code, use a number without parentheses.

  • Steve Dec 14, 2008 @ 13:27

    Dan, you were exactly right, almost. Slackware used bash for both user and root. I ended up with

    export PS1=’e[0;32m$PWD $e[m ‘

    in ~/.bashrc


    export PS1=’e[0;31m$PWD #e[m ‘

    in /root/.bashrc

    and I not only get what I want, but I get Christmas colors, too. Thanks for the tip and this article.

    • sfp Oct 1, 2013 @ 7:31

      try ‘$’, PS1=’…what_ever_you_want…$’

  • Reg Whitton Jan 6, 2009 @ 12:07

    @ SimpleSimon

    My answer for question 1:

    PS1='${PWD/????????????????????????????*/...${PWD:${#PWD}-25}} '

    Note: I used 28 question marks otherwise the … could make the string longer. If you reduce it to 25 then use ${#PWD}-22 in the substring length.

    Question 2, answer 1:

    I have tried this out but I can’t recommend it. I would recommend anser 2 below. However it is interesting to show what can be done.

    You need to look at /etc/termcap for your terminal (xterm) in my case, and at the meaning of the tcap codes in terminfo.

    In particular:
    sc – save cursor
    rc – restore cursor
    cm – cursor move
    ce – clear to end of line

    These can take quite a bit of understanding, but my “cm” is E[%i%d;%dH which means that in my PS1 that e[1;1H would move the cursor to the top of the screen (the first number is the row). If there is no %i in the “cm” then numbers start from zero.

    My “sc” is E7
    My “rc” is E8
    My “ce” is E[K

    So setting PS1 thus:

    PS1='${PWD/????????????????????????????*/...${PWD:${#PWD}-25}} e7e[1;1Hwe[Ke8'

    Will write the current directory on the top line of the screen.

    Next you need to ensure that the checkwinsize is set.

    shopt -s checkwinsize

    You might put it in your “.bashrc” . This sets the LINES and COLUMNS variables after every external command.

    Now try setting PS1 thus:

    PS1='${PWD/????????????????????????????*/...${PWD:${#PWD}-25}} e7e[$LINES;1Hwe[Ke8'

    This will write the directory at the bottom left. However, this is not good as using the top line. Once the screen is full, bash and program output will mangle the directory line.

    Hence I recommend answer 2.

    Question 2, answer 2:

    Assuming that you are using a virtual terminal – you can often put the current directory (or other info) into title of the window.

    I use bash on Windows/Cygwin and by default PS1 set thus:

    PS1='[e]0;wa]n[e[32m]u@h [e[33m]w[e[0m]n$ '

    This makes the prompt:

    user@host directory

    in pretty colours and puts the current directory in the title for the xterm or ansi console (rxvt or Windows command window). If you use another terminal emulator you may need to find other command codes that do this.

    This works well except the newline in the prompt can muck up the editing of very long previous commands. However, if you use the answer to question 1 you could remove it.

    PS1='[e]0;wa]n[e[32m]u@h [e[33m]'${PWD/????????????????????????????*/...${PWD:${#PWD}-25}}[e[0m]n$ '

  • milo Feb 12, 2009 @ 5:48

    Use the csh shell … if by mistake u have moved to another shell like bash

  • irvy Apr 15, 2009 @ 1:01

    How can I get the /home rather than ~ ?

  • Kia May 1, 2009 @ 20:06

    irvy — I think Vivek may have misunderstood you. You get the /home rather than the abbreviated ~ path by using $PWD (instead of w or W for instance). You shouldn’t have to precede it by , either. There are examples above. Good luck.

  • QZ May 27, 2009 @ 7:42

    Hey, I absolutely *love* the desktop background in that example. Waterfall and desert and crazy sky; pure adventure. Can you tell me where to find it or even email me a copy? Thanx!

  • Dominique Michel Jun 8, 2009 @ 18:39

    My fully localised prompt:

    export PS1="e[01;33m# e[01;35mD{%A %e %B %G %R %Z} e[00;31mue[01;32m@e[00;31mh e[01;33mw :e[00mn"

    It give something like:
    # lundi 8 juin 2009 20:15 CEST dom@tuxstudio ~ :

    The # at the beginning associated with the final newline make this prompt absolutely perfect to copy and paste stuffs.

  • salil jain Jun 18, 2009 @ 21:20

    Hey, I just customised a ubuntu liveCD without the XWindows system installed, but the bash that i’m getting has very odd looking fonts , how can i change those? please advise.

  • sharmila Oct 5, 2009 @ 11:18

    how to change the diectory using go function

  • CT Oct 15, 2009 @ 4:18

    @ QZ did you ever get a response back regarding that wonderful wallpaper image?
    I’m interested in it as well! It looks great!

  • Paramjeet singh Oct 20, 2009 @ 7:00

    Thank U for help

  • ahmed Nov 13, 2009 @ 19:49

    I am not getting the desired prompt. this is my .profile
    PS1=”[d t u@h:w ] $ ”
    export PS1

    prompt is the below one:
    [d t u@h:w ] $

    what is wrong I am doing here? any help appreciated.


  • Kunchok Nov 14, 2009 @ 21:23

    Bash treats backslash characters specially in double quoted strings. Try single quotes around the prompt specification
    PS1='[d t u@h:w]$ ‘

  • Ahmed Nov 16, 2009 @ 19:01

    I tried single quotes as below:
    PS1='[d t u@h:w ] $ ‘

    it still gives the same output:
    [d t u@h:w ] $

  • bob Nov 27, 2009 @ 17:40

    ” and ” are different characters, try replacing them using copy/paste.

    My PS1 var is:
    export PS1=”u [W] $ “

  • Ahmed Nov 28, 2009 @ 14:11

    Thanks Bob,

    I tried copy pasting in my .profile, but it is getting copied as export PS1=.u [W] $ .
    “ is replaced by .(dot). which keystroke will type this “?

  • bob Dec 2, 2009 @ 15:10

    You could try copying the character from the ~/.bashrc file itself, for example at lines 5-6:
    # If not running interactively, don’t do anything
    [ -z “$PS1” ] && return

    The double quotes look different on my side and on the site. There are “strait” quotation marks (unicode 0022) and English quotation marks (unicode 201C / 201D). The site converts the first one into the second one.
    Maybe try editing the line with another text editor (nano, vi…) and/or copy the quotation marks from the same file, not from the web site.

    For unicode characters, check:

  • david Jan 19, 2010 @ 0:50

    I set PS1=”[u@h:w]$ ” in my .bashrc file, however, when I type bash at a cmd.exe window the I get

    bash: $’r’: command not found

    – the cursor is located on the [ at the start of the line rather than after the $?
    – why does the $r mean?

    Any help welcomed.

  • John Cochran Feb 8, 2010 @ 14:29

    my issue is that my screen size is 140 characters. Due to my PS1 config, my command line actually starts in column 23, that leaves 117 characters possible. Whenever I use AIX or Solaris, I can fill the entire line, and then go to the next line and keep going until I hit enter or some limit like 512 or something. What drives me up a wall with linux is that it can only show 25 characters, then shifts left or right. How can I get linux to display the entire command line and quit that 25 character shuffle crap.

    • John Cochran Oct 22, 2010 @ 12:45

      You mean no one else has run into this??? Nobody else is bothered by not being able to see the line correctly???????? Why is Linux the only crazy op sys that limits the command line display to 25 characters, even though you can really enter more, you just can’t see it without constantly shifting right or left, and seeing only a segment at a time. Why can’t I change this stupid behavior????

      • Joe Jan 21, 2011 @ 6:06

        @John Cochran
        I’ve never had that problem. It might help if you mentioned what shell and distro you’re using.

        BTW, Linux isn’t an OS. “Linux” refers either to the kernel, or the family of OSs that use the kernel. The kernel probably doesn’t have anything to do with your problem, and it certainly isn’t an issue with the whole family. It’s probably the shell, whichever one you’re using.

        • Cody Apr 22, 2011 @ 12:11

          True, Joe. And not only that he should mention what terminal he’s using and how many rows, cols, the font and so on. That would have been useful to help him, but alas…

          Indeed, the command line can see far more characters in a row without the weird issue he’s mentioning. It’d likely be his terminal and/or font is set improperly. I’ve written about this (well changing fonts) but if you change cols/rows then obviously you’ll have an issue.

          For John: hint: stty -a should show you how many rows and cols its set to. Also look up setfont.

          • John Cochran Apr 22, 2011 @ 12:40

            /home/jpcochr:jpcochr@VMAMN14GLBSMG4 –>stty -a
            speed 38400 baud; rows 52; columns 206; line = 0;
            intr = ^C; quit = ^; erase = ^?; kill = ^U; eof = ^D; eol = ; eol2 = ; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
            -parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts
            -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel
            opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
            isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke
            /home/jpcochr:jpcochr@VMAMN14GLBSMG4 –>can display on my command line, WHY? <

            Actually, I'm not sure how the font could affect this, I use the exact same terminal, ssh to numerous UNIX or SUN servers and the prompts work just fine, but when I'm on a LINUX jump server all I can get is 25 characters, period, regardless of the font. WHY is LINUX limiting the prompt to 25 characters, Why can't I just keep typing and have the prompt go all the way to the end of the screen???

            • John Cochran Apr 22, 2011 @ 12:46

              btw, we use F-Secure SSH Client v5.4 build 34 to gain access to our various servers. We use the exact same window, same settings. Not sure if this helps or not:
              /home/jpcochr:jpcochr@VMAMN14GLBSMG4 –>uname -a
              Linux VMAMN14GLBSMG4 2.6.9-89.0.11.ELsmp #1 SMP Mon Aug 31 11:01:10 EDT 2009 i686 i686 i386 GNU/Linux

              /home/jpcochr:jpcochr@VMAMN14GLBSMG4 –>cat .bash_profile
              # .bash_profile

              # Get the aliases and functions
              if [ -f ~/.bashrc ]; then
              . ~/.bashrc

              # User specific environment and startup programs


              export PATH
              unset USERNAME
              /home/jpcochr:jpcochr@VMAMN14GLBSMG4 –>cat .profile
              MACHINE=”uname -n”
              #stty erase
              set -o vi

              #PS1=”$PWD n
              #whoami: $MACHINE –> ”
              PS1=’$PWD:$USER@$HOSTNAME –>’
              #PS1=’$USER@$HOSTNAME:$PWD –>’
              /home/jpcochr:jpcochr@VMAMN14GLBSMG4 –>

            • Cody Apr 22, 2011 @ 13:15

              Font could effect it on a normal terminal (say at the console) because of size relative to rows/cols (I realize that may not be clearly stated but I write an example later down). I see though that you use a client to ssh in so that may be of less help.

              I can’t say I know for sure but what I wonder is:

              echo $TERM ?
              and what is stty -a (for rows and cols) show on the others (Solaris etc) ? I am pretty sure stty is there though it’s been a long time since i’ve touched BSD, Solaris or any other Unix derivative besides Linux.

              Otherwise all I can say is it’s not Linux itself that’s doing it – it may be a setting in that system though. Unfortunately I don’t have access to a windows machine so I can’t really test that part (the client).

              For reference though, here’s my stty -a output (on a 24″ screen) – my main machine:
              speed 38400 baud; rows 24; columns 80; line = 0;
              intr = ^C; quit = ^; erase = ^?; kill = ^U; eof = ^D; eol = ;
              eol2 = ; swtch = ; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
              werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
              -parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts -cdtrdsr
              -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
              -iuclc ixany imaxbel -iutf8
              opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
              isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
              echoctl echoke

              and on my server (also linux, different distro) and smaller monitor:

              rows and cols is different (as I changed font yesterday) but it was before that change actually the same as above.

              But indeed on the console font differences can change the amount of rows and cols.

              F-Secure. Hmm. I cannot remember if they have a Linux client or not but I’ll check. I unfortunately only use Xterm or the console itself.

              Crazy idea: what if you start a new shell (e.g., su – user) ?
              One other thought: screen shot of this phenomenon ? I can easily imagine this isn’t being interpreted on my part correctly.

              • Cody Apr 22, 2011 @ 13:18

                One other thing: what is your PS1 variable set to ?
                I missed that part (how is another question – maybe that I wrote that at around 5 or so in the morning). Maybe it’s to do with that even (or that and a combination of something else).

                Could very well be relevant.

                • John Cochran Apr 22, 2011 @ 13:54

                  I provided my profile information and the PS1 defintion above. I also posted a sample of what my line looks like, but I don’t think it came out visually very well on this web site. I will try again.

                  on LINUX,:
                  /home/jpcochr:jpcochr@VMAMN14GLBSMG4 –>
                  /home/jpcochr:jpcochr@VMAMN14GLBSMG4 –>Now is the time for all good men to c >
                  ksh: Now: not found
                  /home/jpcochr:jpcochr@VMAMN14GLBSMG4 –> all good men to come to the aid of t +
                  ksh: Now: not found
                  /home/jpcochr:jpcochr@VMAMN14GLBSMG4 –>me to the aid of their party! now is the time for all good men to come to the aid of their party!

                  • John Cochran Apr 22, 2011 @ 13:56

                    well, that didn’t work. lets try it separately. on the LINUX server:
                    /home/jpcochr:jpcochr@VMAMN14GLBSMG4 –>
                    /home/jpcochr:jpcochr@VMAMN14GLBSMG4 –>Now is the time for all good men to c >
                    ksh: Now: not found
                    /home/jpcochr:jpcochr@VMAMN14GLBSMG4 –> all good men to come to the aid of t +
                    ksh: Now: not found
                    /home/jpcochr:jpcochr@VMAMN14GLBSMG4 –>me to the aid of their party! <

                    • John Cochran Apr 22, 2011 @ 13:58

                      you note the > meaning more characters after this point
                      the + apparently means more characters on either side of what is displayed
                      and the now is the time for all good men to come to the aid of their party!

                    • John Cochran Apr 22, 2011 @ 14:00

                      this web site is goofing me up. ignore the post below, that is not what I entered.
                      you note above the > at the end of the line, meaning more characters after this point, but I can’t display them until I move the cursor through the line, then it all shifts left.
                      then there is the + sign denoting more characters on either side of what is actually displayed,
                      then the < sign denoting more characters before what is displayed.

                    • John Cochran Apr 22, 2011 @ 14:02

                      from SUN, I get this:
                      jpcochr: ceas1u2 –> now is the time for all good men to come to the aid of their party!

                    • Cody Apr 22, 2011 @ 14:15

                      Well a few thoughts but this is about all I can think of (I think part of the issue is I don’t really follow the issue – as in where or what is being limited).

                      1 – I know with bash you can put newlines into prompts and it works ok. By putting n in the prompt (just like in C and other languages).
                      2 – Did I see ksh ? You’re using kornshell then ? It’s been over 10 years since I’ve used it i think. Close to if not.
                      3 – What IS the actual issue ? What is limited ? Are characters not being displayed right, or what ?

                      I think though that this should probably be addressed elsewhere; as much as I’d like to help I don’t want to turn this into a support place – not my blog to do that. Suggestion then: find a forum that may help (maybe even f-secure would have ideas for all I know).

                      Kind regards.

                    • Cody May 23, 2011 @ 13:43

                      I just came across this link below. It may explain your issue (I admittedly did not read your post in full again, but if memory serves it is something about it being a long prompt. You may find the following useful:

                      The general idea may be the same (length of prompt of bash). Either way, not a bad read (the whole document I mean).

  • Shanmugapriyam Feb 15, 2010 @ 13:28

    I want to diaplay a masked edit mask always i.e After we entered digits, the mask should dispaly.
    For date format: _/_ _/_ _ _ _
    This underscore should display even after we enter the date i.e we have to set underscore as below every digit we enter..
    Is there is any way to do this? Pls reply.

  • Benjamin Lu Apr 23, 2010 @ 0:30

    My example:
    1). Put the line below to /etc/profile, save it:
    export PS1=”(`date`) 33[33m]n[e[1;36;40mu@e[1;31;40mH:e[1;33;40mw]e[1;0mnbash$ ”
    2). after re-login, your system will show time stamp in one line in ( ), the next line will show full path with userid@full_hostname:working_dir_in_fullpath in [ ].
    (Thu Apr 22 16:39:55 PDT 2010)
    3). in the example above, I set the color as: Blue for userid, Red for hostname, and orange for working dirs. You can have diff colors by changing colo code in the example. This works in both Unix and Linux systems

    Good Luck


    • Dholly Jun 1, 2010 @ 13:40

      Any other way , where we can change our prompt without using the PS1 and .profile?? I am using Ksh . Please help me on this….

      • Benjamin Lu Jul 26, 2010 @ 20:40

        If you use PS1, remove bash from the PS1 line to avoid using bash. If your shell is ksh defined for your account in /etc/passwd file, after your login, your default shell will be ksh. You can go the same way to change your shell to csh, bsh, or bash as ksh in your user account. Other way, any time you input ksh from command line, your working shell will change to that shell, or you input bash, your working shell will change to bash, but your default shell will still remain as ksh.

  • superuser May 16, 2010 @ 23:29

    Thanks a lot, this helped me

  • daeji May 26, 2010 @ 11:25

    any chance you could post your firepower .bashrc?

  • jhosa Jun 17, 2010 @ 14:24

    how to change the prompt of the X-Terminal window of sun solaris 8

    e.g. change prompt fsr40% to fsr50%

  • Chris Jul 26, 2010 @ 18:32

    I am also interested in knowing where that desktop wallpaper / background came from, and where I might be able to obtain a copy of it. It’s beautiful! 🙂

  • openemr advocate Oct 21, 2010 @ 21:58

    Linux is the best. I love all that you can do to it. I wish more people knew more about it so we could put Microsoft in its place.

  • Young Nov 18, 2010 @ 19:54

    I want to set prompt like PS1=”[t u@h:w]\$ ” for all users in in Ubuntu 10.04 servers.

    If I included this in /etc/bash.bashrc it is overwriting by /home/*/.bashrc file

    How to resolve this?

    Thanks in advance.

  • Stefan Dec 23, 2010 @ 9:27

    Can you post the code for your firepower shell ?

  • JT Mar 31, 2011 @ 17:56

    I would like to change bash prompt font size to have more charactes per line, I’m using default monitor CLI (vga) non-GUI Centos5.5. Any one knows how to do this? Thx. JT

    • Cody Apr 22, 2011 @ 12:17

      JT: I actually just wrote about this yesterday.

      Summary is this:

      Firstly, look in /lib/kbd/consolefonts
      Next, look at setfont(8)
      You can use it like: setfont -C $(tty)

      Lastly if that is one you like, then set SYSFONT to that (minus the extension of .psfu.gz) in /etc/sysconfig/i18n

      Hope that helps (and that the hour it is here didn’t get me).

      • Cody Apr 22, 2011 @ 12:18

        Ehm, after the $(tty) add the font file. Stupid me forgot html could get eaten!

        • JT Apr 22, 2011 @ 15:05

          Thank you very much Cody, your info help me a lot to understand where/how to change console fonts. Thanks again!!

      • Vicky Nov 13, 2016 @ 20:19

        Hello, can you say how to make font size of prompt larger so that it is easy to identify in a bunch of text? I am using Ubuntu 16.04. And where did you write more about this?

        Thank you

  • Pedro Inácio Oct 3, 2011 @ 13:15


  • Thor Nov 17, 2011 @ 15:02

    For those asking about the wallpaper, you can find it using google image search (you can drag and drop images to search for similar images. First place I found it on is×1200.html

  • deepak Jan 5, 2012 @ 19:58

    how to do $HIBI
    i tried PS1=”$HIBI” it changes the prompt to blank character

  • marin Apr 1, 2012 @ 18:05

    When i put in a string to my PS1=

    after i login all i get is this;


    why do the colors not come up but strictly the codes?

    Any help is greatly appreciated.

  • Nathaniel Mills Jun 26, 2012 @ 17:42

    When I scp to a machine where I’ve used tput to alter the prompt color, I get a message:

    tput: No value for $TERM and no -T specified

    Is there a way to avoid this? Echoing $TERM on my local window where I issued the scp command shows xterm (e.g., I’m running a bash Konsole on a kde desktop)

  • Harshad Jan 6, 2013 @ 18:45

    Thank you very much for your guide. It helped me remove the bash prompt. 🙂

  • Algabe Mar 17, 2013 @ 17:00

    Aquí les dejo unos que hice.

    #PS1='[e[1;34m]┌─[e[1;32mue[m@e[1;33mhe[1;34m]─[e[mle[1;34m]─[e[mte[1;34m]n└─[e[0;36mwe[1;34m]─[e[m$e[1;34m]e[m '
    PS1='[e[1;32m][u[e[m]@[e[1;33m]h[e[1;34m] w][e[1;36m] $[e[1;37m] '
    PS1='┌──[u@h:w][t]n└──[$] '
    PS1='┌─[u][A][w]n└─[$] '
    PS1='[33[0;41m] u@h[33[01;36m]W $ [33[00m] '
  • Etienne F. Marsh Mar 20, 2013 @ 13:46

    Dude! Can you please provide me a link to your outstanding desktop background ?

    Holy mother it is so beautiful, view from above and the magnificient waterfall…

    BTW thanks for the tuto too 🙂

  • Miquel Aug 25, 2013 @ 23:40

    La meva contribució/ My contribution:
    PS1=”[e[4;44mu@e[4;44mh e[1;44m! e[4;32m@ [e[4;41m]w e[0m]e[0mn$ ”


  • Carlos Vazquez Sep 5, 2013 @ 20:13

    I don’t know if something changed in CentOS 6.4, but when I edit bashrc, it says this at the top:
    # It’s NOT a good idea to change this file unless you know what you
    # are doing. It’s much better to create a shell script in
    # /etc/profile.d/ to make custom changes to your environment, as this
    # will prevent the need for merging in future updates.

    So I took its advice and created in /etc/profile.d/
    $ vi /etc/profile.d/

    And I added the PS1 = to it:
    PS1=”[u@h:w ] $ “

    • Cody Sep 7, 2013 @ 2:43

      I remember that for a long time. Of course, CentOS 6.4 has been out for a long time too (I am thinking it’s getting fairly close to CentOS 6.5 time frame although I wouldn’t trust myself on that without looking, either). I know Fedora has that too. And it makes sense as well. It’s more modular and allows for not cluttering up the main configuration. Not that using diff and vi (or vim or even vimdiff) is hard but it does add to the time and additional task (which adds to the places where errors can crop up) and most system configuration stuff does have its own way of reading from the environment (another two examples: /etc/init/ and /etc/bash_completion.d/). And just as a fyi (though I suspect you might have guessed): it doesn’t have to be called ‘’ – as in it reads from files in the directory (I want to say it checks for the extension although I’m not sure if I am making that up or remembering it wrong – nope, didn’t remember it wrong: a quick look shows that it reads in files ending in .sh in /etc/profile.d/).

      Personally though I would argue that if you’re going to adjust things like the prompt on a global level then it would be best to have it in a (example) bash function or at least determine if the terminal is capable of what you are adding (although yours is basic enough to probably not matter much) – or both.

  • reveal May 29, 2014 @ 17:28

    echo $PS1
    [u@h W]$
    [root@centos ~]#

  • Leonardo Jul 7, 2014 @ 0:41

    Is there a way to set PS1 to the default if it is changed? I have not set PS1 yet but I just want to know in case I decide to do so.

    • Cody Aug 20, 2014 @ 13:06

      Yes. Open another shell and/or logout (or ‘exit’ – either ‘logout’ or ‘exit’ should work) and then log back in. PS1 isn’t stored to disk except on a global level or user basis (e.g., user’s profile …). If you’re in a gui just open another shell (tab, window, whatever). PS1 is an environmental variable and nothing else.

      Another option:
      echo $PS1
      to see what it is. Or…
      export PROMPT=$PS1
      … do whatever …
      (as long as same session should work fine. That is, it should work fine if it comes out okay on this page… if not I’ll see about getting the html character code)

  • Praveen J Kumar Aug 12, 2014 @ 20:44

    I want to get a prompt message with yes or no option before removing my directory!!!Can smeone help me out with this???

    • Cody Aug 20, 2014 @ 12:45

      This is the command prompt, as in where you type any command. rm is irrelevant here. But as a couple of hints:
      – use rm -i instead (and no, that’s not perfect because you do need the -r option too but if you want to know how to remove a directory interactively you should know how to remove a directory).
      – Better yet: don’t mindlessly type commands. That’s the only good choice. Trust me on that. If you don’t then you’re bound to run in to troubles at times and it could be ugly (and as an aside: backup! regularly. as in daily. as in as long as any data changes …).

  • Christmas Aug 31, 2014 @ 0:17

    Just a comment, in your example you put \u and \W, (I guess you thought you needed the escape character) but you don’t need to put those there. Good tutorial though!

  • Irfan Dec 10, 2014 @ 4:22

    Thank you for sharing this information. Command prompt, or terminal, in its default form certainly keeps the user in an uneasy state: I want to change an aspect or two, but how. This tutorial provides at least a few useful hints or answers, thanks again.

  • D'go Sep 2, 2015 @ 11:18

    Hello I am attempting to generate a bash scrip that prompts me at loggin to change my PS1 –
    However, I am running into an issue w/ the code.

    #the point of this script is to that it automates and changes my prompts every day
    msg1=”What do you feel like adding today :”
    echo $msg1
    read PROMPTT

    after entering my promptt i get: line 6: PS1=”{PROMPTT}”: syntax error: operand expected (error token is “”{PROMPTT}””)

    What is wrong with my command?

    • Dan Stromberg Nov 28, 2016 @ 3:10

      Try something like:
      export PS1=”$PROMPTT”

  • Dan Stromberg Nov 28, 2016 @ 3:04

    bash 4.4 includes a $PS0, which is used -before- each command.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum