3

There are a couple of defaults in the standard Linux shell, bash, that I think need some history brought out. This question is about the prompt.

The default prompt in bash in many Linux distros is [\u@\h \W]\$

For those who can't parse that, it looks like this for a typical user:

[staticsan@walcen files]$ _

The biggest problem with this is that it only tells you the name of the current directory. "files" could just as easily be /var/www/files/ as /home/staticsan/files (and that's a simple example). A full path makes more sense, so I have to change it every time I setup a new box or create a new user.

So why is the default set to what it is?

2
  • Which distros and shells is this the default for? Ubuntu, for example, defaults to no square brackets, user and full path for BASH, i.e. from PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
    – mas
    Sep 4, 2009 at 6:34
  • It's the default in RedHat and derived, which is the standard one used by a lot of corporations. RedHat is also the default for most hosting services.
    – staticsan
    Sep 6, 2009 at 23:18

5 Answers 5

6

The answer is simple — it's a relic of times where terminals were 80 characters wide. Look at your own example — username & host occupies already 16 chars. With additional brackets and spaces there's 20 chars already, and we haven't counted the directory name yet.

And the directories can have pretty long names, too. Your example path counts 21 chars and it's only three directories deep. In such case, on 80-char terminal that prompt will occupy half of the screen width.

Of course, today terminals are wider and that's why many users & distros switch to longer prompts. But there's still some which use a narrower prompt to leave the user more space to type.

2
  • The realization that this is prevalent in RedHat also makes sense: they really don't like updating things like this for fear of "upsetting what people are used to". I kid you not: I received that response from a feature request some years ago. I no longer install RedHat if I can avoid it.
    – staticsan
    Sep 6, 2009 at 23:21
  • 1
    Since it's trivial to customize this on a per-user or per-host basis, that seems quite petty. Mar 7, 2013 at 16:38
7

A possible answer would be that

[my_name@my_machine /var/www/html/my_site/my_subdir/another_subdir/yet_another_subdir/and_more_subdirs_yet/see_here/another_subdir/etc $] _

would be a very inconvenient for you to work with

1

I will not answer to the "why" part of the question.

But I'll give you a hint on how to change the default behavior for all of your future user accounts:

You can change the defaults files (and files layout too) use when creating users by changing files in /etc/skel/

So change the PS1 variable in the /etc/skel/.bashrc and it will be the default for new users.

2
  • Look too at /etc/profile where a lot of these things can be changed as well.
    – sybreon
    Sep 4, 2009 at 7:02
  • I know that for my own boxes, but I can't change that on the numerous boxes I have accounts on that I don't look after. :-)
    – staticsan
    Sep 6, 2009 at 23:19
1

I like

PS1="\h \d \t \w\n\u > "

which results in:

myserver Mon Sep 07 07:43:11 /u08
root >

So you get hostname, date and time, full path, and then username on a new line, with the prompt. That is to minimize line wrap deep in directories. I'm in and out of boxes all day, so all I can do to keep it straight is good. I also have putty set to log everything. I can go back and look at logs, and see exactly what I was doing when. Also handy for figuring out sequences of events in several terminal windows at once.

1

I've gone into my /etc/skel and edited the default prompt to the following:

\[\033[33m\][\u@\[\033[1;31m\]\h]\]\033[0m {\W}\n\033[1;34m\]\w\]\033[0m >

it looks like this:

[user@hosts] {currentdir}
/path/to/current/dir >

plus color - because I like color :)

But yes - the "why" is related to small terminals, and now a lack of willingness to change from the status quo.

update without color

[\u@\h] {\W}\n\w >
3
  • 1
    Who the hell decided that \[\033[33m\][\u@\[\033[1;31m\]\h]\]\033[0m {\W}\n\033[1;34m\]\w\]\033[0m > was a sensible string for encoding a default prompt? I've seen simpler regexes! I miss my good old "prompt $p$g" Sep 7, 2009 at 6:21
  • (that's not a comment on that string, but the general method of setting the display for the prompt) Sep 7, 2009 at 6:23
  • added a version without the octal color codes; personally, the escape codes make sense to me.. \u for user, \h for host, \W for working dir, \w for working path, etc :)
    – warren
    Sep 7, 2009 at 7:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .