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

by on June 2, 2007 · 87 comments· LAST UPDATED October 9, 2007

in , ,

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
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 : "
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 $ "
Output:

Sat Jun 02 server $ 

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

[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
or
$ 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] $"
fi

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*
OR
# 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):
flower.png

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:

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 87 comments… read them below or add one }

1 akashdeep June 3, 2007 at 9:12 am

LOL .. nice your command is my wish

Reply

2 Mike July 21, 2011 at 8:47 pm

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?

Reply

3 Name November 6, 2013 at 12:41 pm

Weird…

Reply

4 jack January 29, 2014 at 12:03 pm

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

Reply

5 Cody January 31, 2014 at 12:35 am

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.

Reply

6 Brandon February 14, 2014 at 8:58 pm

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

Reply

7 Cody February 16, 2014 at 3:00 am

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

Reply

8 James February 20, 2014 at 8:40 pm

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

Reply

9 Cody March 1, 2014 at 5:12 pm

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.

Reply

10 Kirk Strauser June 13, 2007 at 1:01 pm

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
prc[abbrevpath]='%{${fg[red]}%}%B%45

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.

Reply

11 SimpleSimon November 27, 2007 at 2:47 am

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?

Reply

12 chika January 24, 2008 at 3:51 pm

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

Reply

13 chika January 26, 2008 at 5:42 pm

hey chika do this on your console

PS1=”\d $”

Reply

14 oscar April 17, 2008 at 8:51 pm

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

Reply

15 Jamie April 23, 2008 at 12:24 am

@ SimpleSimon

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

Example:
# 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\$ ”

HTH,
Jamie

Reply

16 Reddy September 2, 2008 at 10:12 am

Thank you very much

Reply

17 Steve November 6, 2008 at 4:20 pm

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 $”
fi

but after suing to root I still get

/home/steve $

How would I fix this?

Reply

18 felipe1982 September 7, 2011 at 4:38 am

> 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
Password:
~ #

Reply

19 Dan November 25, 2008 at 10:07 pm

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.

Reply

20 Balaji November 27, 2008 at 8:15 pm

hi,

how to accept the prompt value into a variable.

x=echo $PS1 : this is not working

thanks,
Balaji

Reply

21 nixCraft November 27, 2008 at 8:20 pm

Balaji,

Use following code

x=$(echo $PS1)
echo $x

Reply

22 Balaji November 27, 2008 at 8:31 pm

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
#!/bin/ksh

x=$(echo $PS1)

echo $x

exit (1)

Reply

23 Jan January 17, 2012 at 11:14 am

try x=`echo $PS1`

Reply

24 nixCraft January 17, 2012 at 11:27 am

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

x="$PS1"
echo "x is $x"

Reply

25 Bret Sutton November 30, 2008 at 9:46 am

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.

Reply

26 Steve December 14, 2008 at 1:27 pm

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

and

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.

Reply

27 sfp October 1, 2013 at 7:31 am

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

Reply

28 Reg Whitton January 6, 2009 at 12:07 pm

@ 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:

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

Reply

29 milo February 12, 2009 at 5:48 am

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

Reply

30 irvy April 15, 2009 at 1:01 am

How can I get the /home rather than ~ ?

Reply

31 nixCraft April 15, 2009 at 7:50 am

cd /home

Reply

32 Kia May 1, 2009 at 8:06 pm

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.

Reply

33 QZ May 27, 2009 at 7:42 am

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!

Reply

34 Dominique Michel June 8, 2009 at 6:39 pm

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 dom@tuxstudio ~ :


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

Reply

35 salil jain June 18, 2009 at 9:20 pm

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.
Thanks
~Salil

Reply

36 sharmila October 5, 2009 at 11:18 am

how to change the diectory using go function

Reply

37 CT October 15, 2009 at 4:18 am

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

Reply

38 Paramjeet singh October 20, 2009 at 7:00 am

hii
Thank U for help

Reply

39 ahmed November 13, 2009 at 7:49 pm

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.

Thanks

Reply

40 Kunchok November 14, 2009 at 9:23 pm

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

Reply

41 Ahmed November 16, 2009 at 7:01 pm

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

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

Reply

42 bob November 27, 2009 at 5:40 pm

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

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

Reply

43 Ahmed November 28, 2009 at 2:11 pm

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

Reply

44 bob December 2, 2009 at 3:10 pm

@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:
http://triggertek.com/r/unicode/0020-007F
http://triggertek.com/r/unicode/2000-206F

Reply

45 david January 19, 2010 at 12:50 am

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

C:\utils>bash
bash: $’\r’: command not found
[david@DESKTOP:/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.
Thanks.
david

Reply

46 John Cochran February 8, 2010 at 2:29 pm

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.

Reply

47 John Cochran October 22, 2010 at 12:45 pm

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

Reply

48 Joe January 21, 2011 at 6:06 am

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

Reply

49 Cody April 22, 2011 at 12:11 pm

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.

Reply

50 John Cochran April 22, 2011 at 12:40 pm

/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???

Reply

51 John Cochran April 22, 2011 at 12:46 pm

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
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
unset USERNAME
/home/jpcochr:jpcochr@VMAMN14GLBSMG4 –>cat .profile
ME=”whoami”
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 –>

Reply

52 Cody April 22, 2011 at 1:15 pm

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.

Reply

53 Cody April 22, 2011 at 1:18 pm

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.

Reply

54 John Cochran April 22, 2011 at 1:54 pm

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!

Reply

55 John Cochran April 22, 2011 at 1:56 pm

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

Reply

56 John Cochran April 22, 2011 at 1:58 pm

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!

57 John Cochran April 22, 2011 at 2:00 pm

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.

58 John Cochran April 22, 2011 at 2:02 pm

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

59 Cody April 22, 2011 at 2:15 pm

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.

60 Cody May 23, 2011 at 1:43 pm

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:
http://tldp.org/HOWTO/Bash-Prompt-HOWTO/nonprintingchars.html

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

61 Shanmugapriyam February 15, 2010 at 1:28 pm

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.

Reply

62 Benjamin Lu April 23, 2010 at 12:30 am

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 userid@full_hostname:working_dir_in_fullpath in [ ].
(Thu Apr 22 16:39:55 PDT 2010)
[your_userid@your_host.com:~]
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

Ben

Reply

63 Dholly June 1, 2010 at 1:40 pm

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

Reply

64 Benjamin Lu July 26, 2010 at 8:40 pm

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.

Reply

65 superuser May 16, 2010 at 11:29 pm

Thanks a lot, this helped me

Reply

66 daeji May 26, 2010 at 11:25 am

any chance you could post your firepower .bashrc?

Reply

67 jhosa June 17, 2010 at 2:24 pm

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

e.g. change prompt fsr40% to fsr50%

Reply

68 Chris July 26, 2010 at 6:32 pm

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

Reply

69 openemr advocate October 21, 2010 at 9:58 pm

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.

Reply

70 Young November 18, 2010 at 7:54 pm

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.

Reply

71 Stefan December 23, 2010 at 9:27 am

Can you post the code for your firepower shell ?

Reply

72 JT March 31, 2011 at 5:56 pm

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

Reply

73 Cody April 22, 2011 at 12:17 pm

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

Reply

74 Cody April 22, 2011 at 12:18 pm

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

Reply

75 JT April 22, 2011 at 3:05 pm

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

Reply

76 Pedro Inácio October 3, 2011 at 1:15 pm

Thanks

Reply

77 Thor November 17, 2011 at 3:02 pm

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
http://wallpapers.brothersoft.com/epic-waterfall-71081-1920×1200.html

Reply

78 deepak January 5, 2012 at 7:58 pm

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

Reply

79 marin April 1, 2012 at 6:05 pm

When i put in a string to my PS1=

after i login all i get is this;

\[33[0;32m\][\[33[1;32m\]\u\[33[0;32m\]@\[33[1;32m\]freebsd\[33[0;32m\]:\[33[1;36m\]/usr/home/marin\[33[0;32m\]]

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

Any help is greatly appreciated.

Reply

80 Nathaniel Mills June 26, 2012 at 5:42 pm

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)

Reply

81 Harshad January 6, 2013 at 6:45 pm

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

Reply

82 Algabe March 17, 2013 at 5:00 pm

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\] '

Reply

83 Etienne F. Marsh March 20, 2013 at 1:46 pm

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

Reply

84 Miquel August 25, 2013 at 11:40 pm

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\$ ”

II*II

Reply

85 Carlos Vazquez September 5, 2013 at 8:13 pm

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 custom.sh 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 custom.sh in /etc/profile.d/
$ vi /etc/profile.d/custom.sh

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

Reply

86 Cody September 7, 2013 at 2:43 am

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 ‘custom.sh’ – 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.

Reply

87 reveal May 29, 2014 at 5:28 pm

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

Reply

Leave a Comment

Tagged as: , , , , , , ,

Previous post:

Next post: