Most Unix shells let you customize the command prompt. The traditional
prompt is just a
#, for normal users or the root user,
respectively. A short prompt made sense when using Teletype terminals
at 110 bit/s, or 10 characters/second, when a longer prompt might have
taken a second or two to print.
These days, the length of a prompt is no longer a speed issue, and you can even get colours. This article gives a taste of the possibilities, for the Bash shell. For other shells, look into their documentation. The Zsh shell is especially powerful in this area.
In the Bash shell, you change the prompt by setting the
to the value you want. You can use various escape sequences for
dynamic content. For example:
\h the hostname up to the first `.' \t the current time in 24-hour HH:MM:SS format \w the current working directory, with $HOME abbreviated with a tilde
See the bash manual page for the full list (search for "PROMPTING").
As an example, set PS1 like this:
After this, the prompt will look something like this:
\u will be expanded to the user running the shell,
\h to the
\w to the current working directory (with some shortening
logic, as shown above), and
\$ to either
# depending on
whether the user is root or not.
You can also set the prompt even more dynamically, by setting the
PROMPT_COMMAND variable. Bash will evaluate the contents of that
variable as shell commands, and those commands can, for example, set
PS1 to contain the currently checked out branch of a git repository.
(Doing that is left as a tantalising exercise to the reader.)