How to customize your Linux bash prompt

Usually, when I find any cool tips/hacks for Linux, I try them once and right afterwards I forget how to do them!😦 In order to keep as part of the stuff I like and judge interesting (and practice my English), I decided to start to writing them here in my blog. Then, this is going to be my first post about Linux Hacks.

xkcd:Sandwich -> http://xkcd.com/149/

I think that most of the time Linux users prefer to use Command Line (CLI) to run administrative routines, manage files, and install programs, instead of Graphical User Interfaces (GUI). That is when some people may say: “What the hell, man? This is so ugly and complicated! Why don’t you try something easier? Windows perhaps!”. In fact, do some simple tasks via CLI might be way harder than using GUI, also, it may not be always as cool as on movies…

Command Line Interface on Matrix -> http://nmap.org/movies/

In this sense, I am going to show a little hack you can do in your bash that can at least make it look more cool. When you open a terminal, a file named .bashrc contains most of the parameters used to setup your bash sessions. This file can be found in your home directory (~/.bashrc). Open it and you will find a sort of variables. The variable $PS1 keeps the template used to define the way your bash is going to be shown. By default, your bash prompt may look like this:

userName@hostName /home/userName/

There you will see your username, the hostname of the machine you are accessing, and the current directory. However, you can change it by editing the $PS1 variable and make it look like this:

(root@curiosity-HP) → ☢

or even like this:

damascenodiego@curiosity-HP [18:14:58]>

To do this, you just need to choose the special characters you want to use and look for their unicode values.  The value you need to put on $PS1 to show your bash like in the first example is the following:

PS1=$'(\u@\h) \u2192 \u2622 ‘

The special character \u is then replaced by your username, \h by your hostname and the \uXXXX by the unicode character XXXX.  In the first example, the username is root, the hostname is curiosity-HP and the unicode characters are  \u2192 (i.e. →)  and\u2622 (i.e. ☢). In the second example, the string ‘\u@\h [\$(date +%k:%M:%S)]>’ was used. Further informations about special characters can be found at:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s