8 Useful and Interesting Bash Prompts

Many people don’t think of their command prompt as a particularly useful thing, or even pay it much attention. To me, this is a bit of a shame, as a useful prompt can change the way you use the command line. Well I’ve scoured the Interwebs looking for the best, most useful, or sometimes most amusing bash prompts. Here, in no particular order, are the ones I’d be most likely to use on my computers.

Note – to use any of these prompts, you can copy & paste the “PS1=” line directly into your terminal. To make the change permanent, paste the line to the end of your ~/.bashrc file.

1. Show Happy face upon successful execution

This prompt is probably the most amusing one on the list, but remains useful. The idea is that as long as your commands execute successfully, your prompt shows a happy face. Any time a command fails, it shows a sad face instead.


2.Change color on bad command

Here’s one of my favorites. This prompt has it all. Like above, the prompt changes color if your last command failed to run successfully, but it also shortens long paths and contains the bash history number of each command for easy retrieval.


3. Multi lines prompt

If you’re the type who wants to pack your prompt full of information, then here’s the one for you. This one is a multi-line prompt containing date/time, full path, user and host, active terminal, even file count and space usage.

4. Color manage your prompt

There’s nothing particularly fancy about this prompt, other than the good use of color to separate the different pieces of information. As you can see, it provides time, username, hostname, and current directory. Fairly minimal but useful.


5. Show full path

This one’s a nice, clean, minimal 2-line prompt (plus a blank line at the top). You’ve got your full path at the first line and pretty much just the username at the bottom. If you want to remove the blank line at the start of every prompt, just take out the first “\n”.



6. Show background job count

Another nifty 2-liner, but this one’s got some info we haven’t used before. The first line is the normal user@host, with full path. On the second line we’ve got history number and a count of the jobs running in the background.



7. Display directory information

A very elegant and nice looking prompt design. With this one we’ve got user/host, number of jobs, and date/time on the top line. Below that is current directory along with number of files in that directory and their disk usage.



8. My Prompt

And finally, the prompt I personally like to use. It’s a modification of #7, changed to take up less space and include only the information I most want in my prompt. I like the two-line style as it lets me see the full path without reducing the space for my actual commands.


If you’d like to share your prompt, please do so in the comments below.

Joshua Price

Josh Price is a senior MakeTechEasier writer and owner of Rain Dog Software


    1. I’m sure it’s something with the RHEL 5 environment and the encoding it’s sending. Any ideas? I’ve gone a bunch of LANG and TERM settings on the server side…

  1. Great stuff, I like the concepts behind all of them, think I might try out the happy face!

    In the future though, you should use png for images of text, instead of jpg. They’ll look a lot cleaner.

  2. Nice, thanks!

    I accidentally leave stuff backgrounded a bit often, so I’ve used the jobs concept above to get it to OPTIONALLY report the bg jobs if there are any..

    PROMPT_COMMAND=’PS1=”${debian_chroot:+($debian_chroot)}[33[01;32m]u@h[33[00m] [33[01;34m]W[33[00m] `if [ $(jobs | wc -l | tr -d ” “) -gt 0 ]; then echo “[e[1;31m]jobs:j[e[m]”; fi` $ e]30;ha”‘

    craig@homei7 tmp jobs:1 $
    craig@homei7 tmp jobs:1 $ fg
    vi /tmp/tmp1
    craig@homei7 tmp $

    1. Thanks for the suggestion Craig.

      For anyone wanting to try Craig’s prompt, there’s a minor annoyance when posting these kinds of codes where any instance of “backslash zero” gets filtered out, so all cases of “[33” should actually be “[ 033” (extra space added to make sure it doesn’t happen on this reply)

  3. How can I get rid of those commmands again (don’t worry, I like them, but I like to know how to uninstall something before I install it)

    1. If you don’t put it in your .bash_profile or .bashrc file, it won’t load during your next session, so just close the window. Otherwise, just remove it from the file you put it in.

      1. Right, if you paste one of these in your terminal without saving in something like .bashrc it will go away next time you open your terminal. You can also type “source .bashrc” to restore the default prompt.

  4. http://slashdot.org/comments.pl?sid=108424&cid=9219400

    this is the earliest reference i can find

  5. http://slashdot.org/comments.pl?sid=108424&cid=9219400

    this is the earliest version i can find.

  6. My zsh prompt is quite small.

    PROMPT=’%~> ‘

    Displays the canonical path on the left, and the time on the right. If the command is too long, the time is removed.

    ~> cd ../ 9:56
    /home> 9:56

  7. PS1=”[33[01;32m]u@h[33[01;34m] w [33[00m]$(git branch 2>/dev/null | grep ‘^*’ | colrm 1 2)[33[01;34m] $[33[00m] ”

    The interesting thing about my prompt is the git repository branch is named in the prompt

    1. Thanks, I had considered adding a nice git prompt I found but didn’t think all that many people would be interested so I’m glad someone added it in comments.

      Also, for other readers of jrglasgow’s comment, see the comment above regarding broken escape codes

  8. What do I need to do to get the lovely interstitial characters on prompt 7 to display?

    1. I had mixed success with that. Initally it worked perfect for me in xterm and wterm, but looked broken in gnome-terminal. After I tinkered with it, it no longer looked right in any term!

      I would suggest seeing if it looks correct in another terminal (like xterm or wterm)

  9. People seem to be happy, so I will be the first to say that those prompts are horribly ugly.

    Bash is ugly!

    PS: Zsh is not that much more beautiful but the RPROMPT really is damn cool.

  10. Find here my bash prompt that displays git branch and changed files:

    1. Running a ruby script for each prompt display is pretty bold =)

      It is a nice prompt though!

  11. OK, so after dinking around for a while — I’ve come up with one I like. I’d be even happier if I could figure how to get the line characters to work (like in #7)…

    Anyway, this one is based on parts of #1 and #7. It has user@machine, timestamp and directory one one line — and job count, a success/failure indicator (a green :-) on success or a red :-( on failure) on the second line. followed by a $

    PS1=”n[e[30;1m]([e[34;1m]u@h[e[30;1m])-([e[34;1m]t[e[30;1m])-([[e[32;1m]w[e[30;1m])[e[30;1m]n(jobs:[e[34;1m]j[e[30;1m])`if [ $? -eq 0 ]; then echo [e[32m] :-); else echo [e[31m] :-( ; fi`[e[0m] $ ”

    # Now I must get some work done :-)

    1. Perhaps it didn’t paste right, it’s invalid when I try to test.

      As noted in comments above, bash codes don’t always display correctly, not sure if it’s our CMS or some browsers or what. If you’ve got a link to a plain text version or something, please share.

    2. Thanks to Joshua Price’s reply above, I can reduce the frustration level of anybody wanting to try the PS1 I posted — by providing a link to a non-mangled version:


  12. After reading this i took the time to make my promt, and remembered why i am using zsh.
    even though zsh syntax is easier to read i took the idea from one of the /. replies and made this file which i then source from .zshrc

    # Throw it all together

    gives me this
    (0)~%> 0:36[3081]
    (0)~%>return 123 0:37[3081]
    (123)~%> 0:37[3082]

    you can’t see the colors here
    but the return number turns red when not zero

  13. I use bashstyle for this purpose.

  14. I just found this article and decided to piece together from what I could figure out from these examples

    PS1=”[e[37;1m]-{[e[34;1m]u@h[e[37;1m]}-n[e[37;1m]([e[34;1m]w: $(/bin/ls -1 | /usr/bin/wc -l | /bin/sed ‘s: ::g’) files, $(/bin/ls -lah | /bin/grep -m 1 total | /bin/sed ‘s/total //’)b[e[37;1m])n–> [e[0m]”

    It’s a three line prompt. Name and host at the top, directory in the middle and prompt on the last line.

  15. It is basically imbecile to put terminal-dependent escape sequences into prompts. For some reason terminfo and termcap were invented.


  16. Regarding the line characters ? and ? in #7

    They are from the Microsoft cp437 codepage but have been mapped to unicode.
    See: http://en.wikipedia.org/wiki/Cp437

    So as long as you are using a utf-8 enabled terminal (the default on most modern distros) – and your terminal fonts are set up correctly – you can just copy and paste them.

    PS1=”n[e[30;1m]?([e[34;1m]u@h[e[30;1m])-([e[34;1m]j[e[30;1m])-([e[34;1m]@ d[e[30;1m])->[e[30;1m]n??([e[32;1m]w[e[30;1m])-([e[32;1m]$(/bin/ls -1 | /usr/bin/wc -l | /bin/sed ‘s: ::g’) files, $(/bin/ls -lah | /bin/grep -m 1 total | /bin/sed ‘s/total //’)b[e[30;1m])–> [e[0m]”

    Note: There is superfluous “[” after the first dash on the second line in the original code given above.

    1. Ha ha…
      They don’t show up here either…
      Just replace the ?s in the line I gave above with the appropriate characters copied from http://en.wikipedia.org/wiki/Cp437

      Also, you can generate them directly in your terminal with:
      echo -e “xe2x94x8c”
      echo -e “xe2x94x94”
      And I used a long dash
      echo -e “xe2x94x80” which looks better in most terminals.

  17. Continuing the version-control discussion, I posted the bash function which displays the current branch for Git, Mercurial, Subversion and even RCS:


  18. The #7 is *really* expensive resources wise if used in any server environment. Use it with caution and carefully or you may be in trouble someday when less expected (although an unset PS1; exec bash will solve your problem)

  19. I use a multi line prompt that begins with a # as such:

    PS1=”n#–[[e[1;36m]u@h[e[m]]-[[e[1;34m]w[e[m]]-[$(date +%k:%M)]–>n”

    This prompt displays as:

    (with the cursor being down here on a new line)

    This prompt gives me (IMHO) the most important info at a quick glance, what machine I’m on, where I am in it, and the times each of my commands started and finished.

    The real treat in this prompt, is that I can copy a whole screen worth of terminal and just paste it into a shell script with no editing necessary: the # at each prompt line comments it out!

    Try it, you’ll like it, or your money back!

    1. I had considered putting something like that in the article originally, but couldn’t think of a good way to demonstrate the point with screenshots. Thanks!

  20. Another (superior IMHO) way to allow copy/paste of a whole line is a prompt that looks something like

    : your info here ;


    : /path/[vc rev] : exit status ;

    because the : is the bash command that does nothing and the ; terminates that command and allows your command to execute. I use it since I hate multi-line prompts (no offense to those who like them of course).

  21. A lot of interesting ideas here, I’m gonna have to change my .bashrc in the immediate future.

    For the moment this is my bash prompt, after accidentally rebooting my laptop instead of my server for the eighth time in 12 hours, I decided to have separate command promts for a local login and a SSH login:

    if [ -z “$SSH_CLIENT” ]; then
    PS1='[e[0;32m]u[e[m] [e[1;34m]w[e[m] [e[1;32m]$ [e[m][e[0;37m]’
    PS1='[e[0;32m]u[e[m][e[1;31m]@[e[m][e[1;33m]h[e[m] [e[1;34m]w[e[m] [e[1;32m]$ [e[m][e[0;37m]’

    As far as I know (I haven’t done any in depth searching), not many people have done separate prompts for different logins. Does anyone know of anyone else who does this?

    P.S. Sorry for the late comment, I always seam to arrive late to these blog posts. Why does nobody tell me anything until AFTER it happens?

    1. I haven’t seen anyone else change prompt based on SSH status, but many people have one prompt for root and another for users.

      Regarding the delay in finding/commenting, I’d recommend a feed reader to keep active on your favorite blogs. Nearly all blogs (including MTE) have RSS feeds you can send to something like Google Reader.

  22. can somebody help me to combine #8 and #2 ?
    i like the information provided by #8 but also the gimick turning red on a bad command of #2: so how would the code look like for a version of number 8 where all the green parts are turning red after a bad command? can t figure it out on my own.

  23. how about something like this

    if [[ $? = “0” ]]; then color=”\[33[32m\]”; else color=”\[33[31m\]”; fi
    you can put this condition to get the color to set and use the variable color in #8 to set the color.

  24. I use this on most of my accounts, the first line sets the terminal window to read “hostname:username – workingdir” an absolute must when you’ve got 20+ xterm/aterm/rxvt windows open to multiple machines, in one taskbar.

    PS1=”[33]0;h:u – w07]
    [33[1;35m]$(date +%H:%M)
    [33[0m] “

  25. When I use the number 2 I can’t copy remote files using scp.
    I can do an ssh but I can’t copy files, why is that?

    Its very weird because I use that prompt for almost a week :)
    and I lost a two days looking for the error!

    I need some help, here is the scp debug:
    debug1: Next authentication method: password
    debug1: Authentication succeeded (password).
    debug1: channel 0: new [client-session]
    debug1: Entering interactive session.
    debug1: Sending environment.
    debug1: Sending env LANG = en_US.UTF-8
    debug1: Sending command: scp -v -t /tmp
    I’m stuck here.

    Ps: Solved using the old PS1 bash prompt :)

  26. Just to clarify for MacOS X:

    If you want to apply these changes permanently, you don’t need to search or create a .bashrc file, just append the .profile file in you home directory, since MacOS reads this file for environment variables

  27. this is for the Star Wars & Red Dwarf fans out there. I was bored so for fun I put together this prompt. I know it's nothing much, but it suits me :D. Contains mostly codes from here (and the top text is from the 'figlet' program)

    Code : http://pastebin.com/QuLzm7HG

    On a side note, is it possible to get the clock in 12 hour format (would be nice to have am/pm status after it too)

Comments are closed.