How to: Change / Setup bash custom prompt (PS1)

Posted on in Categories Debian Linux, Download of the day, Linux, Linux desktop, Linux distribution, Shell scripting, Suse Linux, Tips, Tuning, Ubuntu Linux, UNIX last updated October 9, 2007

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:
a] Howto customizing a bash shell to get a good looking prompt
b] Configure the appearance of the terminal.
c] Apply themes using bashish
d] Howto pimp out your shell prompt

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 prompt setting?

Simply use echo command, enter:
$ echo $PS1

\\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 –> [[email protected] ~]$
PS1="touch me : "
Output: My new prompt

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’d date and hostname:
PS1="\d \h $ "

Sat Jun 02 server $ 

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

[Sat Jun 02 14:24:12 [email protected]:~ ] $

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’ve 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:
Firepower shell prompt using bashish
(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):

urbandawn - based on an artwork by grevenlx
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

Linux desktop nice visual effect , like transparency, tinting etc
(click to enlarge)

Further readings:

105 comment

    1. 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?

        1. 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.

            1. 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).

            1. 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.

          1. 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.

            1. 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.


              1. 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?

    2. 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?

      1. 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 :)

  1. 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:

    [email protected] [7:54} ~
    :) $

    where "[email protected]" 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.

  2. 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?

    1. 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.

  3. @ 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\$ ”


  4. 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?

    1. > 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 —-
      [[email protected] ~]$ export PS1=”\w \\$ ”
      ~ $ su
      ~ #

  5. 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.

  6. 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)

  7. 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.

  8. 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.

  9. @ 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}} \e7\e[1;1H\w\e[K\e8'

    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}} \e7\e[$LINES;1H\w\e[K\e8'

    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;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ '

    This makes the prompt:

    [email protected] 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;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]'${PWD/????????????????????????????*/...${PWD:${#PWD}-25}}\[\e[0m\]\n\$ '

  10. 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.

  11. 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!

  12. My fully localised prompt:

    export PS1="\e[01;33m# \e[01;35m\D{%A %e %B %G %R %Z} \e[00;31m\u\e[01;32m@\e[00;31m\h \e[01;33m\w :\e[00m\n"

    It give something like:
    # lundi 8 juin 2009 20:15 CEST [email protected] ~ :

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

  13. 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.

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

  15. 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 [email protected]:w ] $

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


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

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

    it still gives the same output:
    [d t [email protected]:w ] $

  18. 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 “?

  19. @Ahmed:
    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:

  20. 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
    [[email protected]:/cygdrive/c/utils]$

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

    Any help welcomed.

  21. 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.

    1. 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????

      1. @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.

        1. 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.

          1. /home/jpcochr:[email protected] –>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:[email protected] –>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???

            1. 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:[email protected] –>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:[email protected] –>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:[email protected] –>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:[email protected] –>

            2. 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.

              1. 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.

                1. 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:[email protected] –>
                  /home/jpcochr:[email protected] –>Now is the time for all good men to c >
                  ksh: Now: not found
                  /home/jpcochr:[email protected] –> all good men to come to the aid of t +
                  ksh: Now: not found
                  /home/jpcochr:[email protected] –>me to the aid of their party! now is the time for all good men to come to the aid of their party!

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

                    1. 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!

                    2. 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.

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

                    4. 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.

  22. 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.

  23. My example:
    1). Put the line below to /etc/profile, save it:
    export PS1=”(`date`) 33[33m\]\n[\e[1;36;40m\u@\e[1;31;40m\H:\e[1;33;40m\w]\e[1;0m\nbash$ ”
    2). after re-login, your system will show time stamp in one line in ( ), the next line will show full path with [email protected]_hostname:working_dir_in_fullpath in [ ].
    (Thu Apr 22 16:39:55 PDT 2010)
    [[email protected]]
    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


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

      1. 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.

  24. 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! :)

  25. 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.

  26. 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

    1. 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).

      1. 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

  27. 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.

  28. 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)

  29. Aquí les dejo unos que hice.

    #PS1='\[\e[1;34m\]┌─[\e[1;32m\u\e[m@\e[1;33m\h\e[1;34m]─[\e[m\l\e[1;34m]─[\e[m\t\e[1;34m]\n└─[\e[0;36m\w\e[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\] '
  30. 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 :)

  31. La meva contribució/ My contribution:
    PS1=”\[\e[4;44m\u@\e[4;44m\h \e[1;44m\! \e[4;32m\@ \[\e[4;41m\]\w \e[0m\]\e[0m\n\$ ”


  32. 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 ] $ “

    1. 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.

  33. echo $PS1
    [\u@\h \W]\$
    [[email protected] ~]#

  34. 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.

    1. 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)

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

    1. 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 …).

  36. 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!

  37. 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.

  38. 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?

Leave a Comment