Make Your Bash Prompt Work For You
· 4 min read

If you work with Linux or Unix-like operating systems like Ubuntu or the MacOS, you might be familiar with Bourne-Again Shell or BASH for short. This article will show you that with a little elbow grease, you can have your BASH prompt work for you and heck maybe have a little fun with it.
People tell me the invention of the GUI (graphical user interface) is the best thing that ever happened to modern computing. I beg to differ. Not all work is accomplished through the GUI nor is it efficient.
I find myself working on the command line for work more and more — managing my servers even my Apple computer. So I get to spend much of my time on the command line. Launching commands like a stenographer recording the latest court drama. I realized very early how powerful the command line could be.
But not having a GUI does not mean you should be happy with the default command prompt. Is this familiar?
Using the table below we can build a BASH prompt that is not only pretty but saves us a few keystrokes as well.
BASH Special Characters Reference
| Special character |
|---|
| \a |
| \] |
| \h |
| \j |
| \n |
| \s |
| \T |
| \A |
| \v |
| \w |
| \! |
| \$ |
| \\ |
| \D{format} |
Change the Bash Prompt
The environment variable we want to modify is PS1.
Using the reference table above we can break down the current prompt as
- \u – the current user
- \h – the computer’s hostname
- \w – the current working directory
Not very useful is it? Let’s change that.
By modifying the PS1 variable and exporting it with the command below we can manipulate the prompt to output anything we want.
Below is my favorite bash prompt which I install for all my servers and even my workstation. I can easily see important details like the hostname – very important if you find yourself managing multiple terminal windows and you can distinguish between windows. This configuration also shows the load averages, the current date and time and the working directory. The color helps to give it contrast to the monotonous black on white default of most terminal windows.
Make it Permanent
To make your BASH prompt permanent, just edit ~/.bash_profile or ~/.bashrc or ~/.profile or run the command
Ideas
- Count the files in the current directory
- Display in blinking colors the last line of a todo list
- Display CPU/Memory/Disk usage
- Display command to pull up a help screen
- Echo a smiley if the system is working in top condition
There you have it, you can now work on the command line with a little bit more help. The key here is to be creative and think of what you want your bash prompt to have. Enjoy!