The user prompt is that thing which you see once you've logged in and the system is waiting for you to do something useful. It may look like this..
..woo-hoo! Or even this..
Exciting eh? No. It's not exciting. It's crap. But you can change all this and get your street-cred back just by adding a single file.
The prompt can be configured to tell you useful stuff, like who you are (saves having to type whoami
all the time, if you swap between users regularly) or which directory you're currently logged into (saves having to type pwd
all the- you get the idea).
There are a few ways to do it. The prompt is influenced by which shell you're currently using and I would urge you to install and use bash
'cos the default csh
is really shit
. Come back when you've finished..
OK so you've wisely installed bash
like I suggested. Log in and type cd
to take you to your home directory (/home/username
if you're logged in as root
). The bash
shell will parse a file called .bash_profile
if it exists in your home directory and you can create this file to influence the shell's behaviour. Thus..
Note the leading dot 'cos it's a hidden file. This is what I've got in my own .bash_profile
..and this is all you'll need too. Yep, just one line. Not so hard eh..
What does it all mean? Well the PS1=
is the bit which tells the shell to configure the prompt somehow. The rest is what you'd like to see.
In the case of my example above, \u
means "the logged in user", @ means @ and \w
means "the currently logged directory". Finally we have the usual "$" sign, which reminds us of all the money (and stress)(and downtime) we're saving from using Unix instead of Windows. And of course, the whole thing's enclosed in double quotes " " just like any self-respecting regular expression should be. Just make sure the prompt's not too
long or your commands may wrap to the next line and that would be no fun.
BASH Prompt Parameters
The following is an extract from the man pages..
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")
\e an ASCII escape character (033)
\h the hostname up to the first `.'
\H the hostname
\r carriage return
\s 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
\u the username of the current user
\v the version of bash (e.g., 2.00)
\V the release of bash, version + patchlevel (e.g., 2.00.0)
\w the current working directory
\W the basename of the current working directory
\! 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
BASH Command Files
When bash is invoked as an interactive login shell, it first reads and executes commands from the file /etc/profile
, if that file exists. After reading that
file, it looks for ~/.bash_profile
, and ~/.profile
, in that order, and reads and executes commands from the first one that exists and is readable.
For more exciting ideas on prompt configuration options, written by really interesting people, do a google search on bsd "set prompt"
Oh, and if you're not picking up the configuration when you su
, use the su -l