Pimp My Bash Prompt

In the next couple lessons here at Nocturnal Slacker v1.0 we’ll be discussing the Bourne Again Shell (BASH) in a bit more detail.

With that in mind, though, how ’bout we play around with a neat trick that will customize your BASH prompt whenever you go to the command line? Sound like fun? OK, here we go…

There’s a file in your /home/<your_username> directory called .bashrc. You’ll need to use the -a (all) option when listing (ls) that directory because the preceding . means it’s a hidden file. So, let’s see how joe would do this…

joe@mysystem:~$ ls -a .bashrc


There we go. So Joe now knows that he does have a .bashrc file in his /home directory. Now, let’s say that Joe wants a cool BASH prompt like mine:


… that shows his username, his operating system, and his working directory. To do this, Joe is going to have to add a little data to his .bashrc file. He’ll edit the file using the VIM command line editor. Remember that from a previous lesson? Here goes Joe…

joe@mysystem:~$ vim .bashrc

And poof! Up comes VIM with the .bashrc file ready to be edited. It’s almost like magic, huh?

# /home/joe/.bashrc

# custom prompt
PS1=”\u | archlinux\w:$ “

Joe is going to edit the .bashrc file to add the little bit in purple that you see above. What that will do is tell BASH to start up the command line with a prompt the shows Joe’s usersname (u), his distribution (ArchLinux) separated by the | (pipe) character; and his working directory (\w). After saving the file, this is what Joe’s command line prompt will look like once he starts his next BASH session:

joe | archlinux~:$

Pretty neato, huh? Remember the ~ denotes the home directory. If Joe was to change directories (cd) to say /boot/grub, then his prompt would now change too to show the new working directory.

joe | archlinux~:$ cd /boot/grub

joe | archlinux/boot/grub:$

Again, pretty neato, huh? This way, Joe will always know what directory he’s in at any given time. That will help prevent Joe from making any command line boo-boos.

That’s it, guys and gals. Pretty simple stuff. See? You’re not near as scared of that mean ol’ command line as you used to be, huh? Use your imagination when customizing your prompt. I’ve seen some pretty cool ones out there. Here’s the one my friend securitybreach and fellow Admin from Scot’s Newsletter Forums – Bruno’s All Things Linux uses:

╔═ comhack@Cerberus 02:27 PM
╚═══ ~/->

How’s that for spiffy? For further reading see HERE and HERE.

Have a great weekend wherever you may be!


14 Comments on “Pimp My Bash Prompt”

  1. comhack says:

    Very nice and informative post Eric!!!

    Also, thanks for the mention!! Although my prompt uses different colors:

  2. comhack says:

    Eh, I will give ya 15% since your a pal.

  3. ROFL!

    Very cool stuff Eric and comhack!

  4. […] faithfully followed by the shell when it is initialized. We’ve seen this already when we were pimping our BASH prompt in a previous article here. I’m over-simplifying, of course. There are other files, be […]

  5. Revku says:

    Ooops..i got this “bash: redhatlinuxw:$: command not found”

    Is their any fix for this Eric??

    • Revku,

      The WordPress Comments area is not really a good place to try to assist folks. If you’d like, register at Scots Newsletter Forums – Bruno’s All Things Linux and post your question there. I’ll be more than happy to help you over at the forum. I’m an Admin there. 🙂

      Here’s the link to Scot’s –> http://forums.scotsnewsletter.com/index.php?

      It’s easy to register. That board/forum has a dedicated community that enjoys helping fellow GNU/Linux Adventurers. Stop on by…


  6. ichase says:

    Great article Eric, have seen many people with “colorized” bash prompt text and not to mention the really neat bash prompt that comhack has. Had not done the research to find out how to do this. Now, thanks to your great lesson…Now I do. 😉


    All the best,


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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s