Ever log into a box, or install a new distro, only to find that the prompt is either just a # or it only provides very minimalistic information? Well, it's easy to change the look of the command prompt by editing the ~/.profile or other appropriate file.
Most shells look at the 'PS1' environment variable to see what the shell prompt should look like. For example, in OpenBSD the root user doesn't have PS1 set to anything, so you get just a '#' as your prompt. Not terribly useful once you start navigating through the file system, opening multiple SSH sessions to edit multiple files, and then you start to loose track of what window is what. So lets add some information to the shell prompt.
Open up the ~/.profile (or ~/.bashrc, or other appropriate file for your distro) with your favorite text editor. I use nano:
Check to see if there is a PS1 variable already set. The line will look something like this:
You can either comment the line out (which I recommend) or just alter it to your preferences.
There are a few different options that you can use to edit the look of your command prompt:
Date in "Weekday Month Date" format.
Complete hostname including domain.
Number of running jobs
Terminal device of the shell (ex: ttyp1)
Name of the shell, e.g. BASH
Current time in 24 hour HH:MM:SS format.
Current time in 12 hour HH:MM:SS format.
Version of Bash
Version of Bash with patch level
Current working directory.
Basename of the current working directory
Insert a '$' (root gets '#' instead)
Current time in 12 hour am/pm format.
Number of commands in the history file (.bash_history).
Number of commands you have executed in your current session.
So lets set up a prompt that looks like '[username@hostname cwd]$ ' with the following:
PS1='[\u@\h \w]\$ '
The 'export PS1' tells the shell to actually use this variable. Log out and log back in, and you will see your new prompt.
Add some color
Now that we have some useful information, we can even add color (assuming your terminal supports color). To add color we get a few new commands:
Start a color combination, where X;X is a combination below
I personally like Green, so I extend my PS1 to look like this:
PS1='\e[0;32[\u@\h \w]\e[m\$ '
So, take all the above information and turn the shell prompt into something that you want to use.