BASH Command Line Linux Ubuntu

How to: Change / Setup bash custom prompt (PS1)

So how do you setup, change and pimp out Linux / UNIX shell prompt?

Most of us work with a shell prompt. By default most Linux distro displays hostname and current working directory. You can easily customize your prompt to display information important to you. You change look and feel by adding colors. In this small howto I will explain howto setup:

  • Customize a bash shell to get a good looking prompt
  • Configure the appearance of the terminal
  • Apply themes using bashish
  • Howto pimp out your shell prompt

Prompt is controled via a special shell variable. You need to set PS1, PS2, PS3 and PS4 variables. If set, the value is executed as a command prior to issuing each primary prompt.

  • PS1 – The value of this parameter is expanded (see PROMPTING below) and used as the primary prompt string. The default value is s-v$ .
  • PS2 – The value of this parameter is expanded as with PS1 and used as the secondary prompt string. The default is >
  • PS3 – The value of this parameter is used as the prompt for the select command
  • PS4 – The value of this parameter is expanded as with PS1 and the value is printed before each command bash displays during an execution trace. The first character of PS4 is replicated multiple times, as necessary, to indicate multiple levels of indirection. The default is +

How do I display current prompt setting?

Simply use echo command, enter:

$ echo $PS1


\u@h \W]\$

How do I modify or change the prompt?

Modifying the prompt is easy task. Just assign a new value to PS1 and hit enter key:
My old prompt –> [admin@105r2 ~]$

PS1="MyNewPrompt : "

Output: My new prompt

MyNewPrompt : 

So when executing interactively, bash displays the primary prompt PS1 when it is ready to read a command, and the secondary prompt PS2 when it needs more input to complete a command. Bash allows these prompt strings to be customized by inserting a number of backslash-escaped special characters that are decoded as follows:

  • a : an ASCII bell character (07)
  • d : the date in “Weekday Month Date” format (e.g., “Tue May 26”)
  • D{format} : the format is passed to strftime(3) and the result is inserted into the prompt string; an empty format results in a locale-specific time representation. The braces are required
  • e : an ASCII escape character (033)
  • h : the hostname up to the first ‘.’
  • H : the hostname
  • j : the number of jobs currently managed by the shell
  • l : the basename of the shell’s terminal device name
  • n : newline
  • r : carriage return
  • s : the name of the shell, the basename of $0 (the portion following the final slash)
  • t : the current time in 24-hour HH:MM:SS format
  • T : the current time in 12-hour HH:MM:SS format
  • @ : the current time in 12-hour am/pm format
  • A : the current time in 24-hour HH:MM format
  • u : the username of the current user
  • v : the version of bash (e.g., 2.00)
  • V : the release of bash, version + patch level (e.g., 2.00.0)
  • w : the current working directory, with $HOME abbreviated with a tilde
  • W : the basename of the current working directory, with $HOME abbreviated with a tilde
  • ! : the history number of this command
  • # : the command number of this command
  • $ : if the effective UID is 0, a #, otherwise a $
  • nnn : the character corresponding to the octal number nnn
  • \ : a backslash
  • [ : begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt
  • ] : end a sequence of non-printing characters

Let us try to set the prompt so that it can display today’d date and hostname:
PS1="d h $ "

Wed Dec 02 ServerName $ 

Now setup prompt to display date/time, hostname and current directory:
$ PS1="[d t u@h:w ] $ "

[Wed Dec 02 18:54:07 admin@ServerName:~ ] $

How do I add colors to my prompt?

You can change the color of your shell prompt to impress your friend or to make your own life quite easy while working at command prompt.

Putting it all together

Let us say when you login as root/superuser, you want to get visual confirmation using red color prompt. To distinguish between superuser and normal user you use last character in the prompt, if it changes from $ to #, you have superuser privileges. So let us set your prompt color to RED when you login as root, otherwise display normal prompt.

Open /etc/bashrc (Redhat and friends) / or /etc/bash.bashrc (Debian/Ubuntu) or /etc/bash.bashrc.local (Suse and others) file and append following code:

# vi /etc/bashrc


$ sudo gedit /etc/bashrc

Append the code as follows

# If id command returns zero, you’ve root access.
if [ $(id -u) -eq 0 ];
then # you are root, set red colour prompt
PS1="\[$(tput setaf 1)\]\u@\h:\w #\[$(tput sgr0)\]"
else # normal
PS1="[\u@\h:\w] $"

Close and save the file.

You can also create complex themes for your bash shell using bashish. Bashish is a theme enviroment for text terminals. It can change colors, font, transparency and background image on a per-application basis. Additionally Bashish supports prompt changing on common shells such as bash, zsh and tcsh. Install bashish using rpm or apt-get command:
# rpm -ivh bashish*
# dpkg -i bashish*
Now start bashish for installing user configuration files:
$ bashish
Next you must restart your shell by typing the following command:
$ exec bash
To configure the Bashish theme engine, run
$ bashishtheme
basish in action (screenshots from official site):
urbandawn - based on an artwork by grevenlx
Finally, you can always use aterm or other terminal program such as rxvt. It supports nice visual effect , like transparency, tinting and much more by visiting profile menu. Select your terminal > click on Edit menu bar > Profiles > Select Profile > Click on Edit button > Select Effects tab > Select transparent background > Close.

BASH Command Line Linux

BASH Shell change the color of the shell prompt in Linux or UNIX

You can change the color of your shell prompt to impress your friend or to make your own life quite easy while working at command prompt.
In the Linux default shell is BASH.
Your current prompt setting is stored in PS1 shell variable. There are other variables too, like PS2, PS3 and PS4.
Bash displays the primary prompt PS1 when it is ready to read a command, and the secondary prompt PS2 when it needs more input to complete a command. Bash allows these prompt strings to be customized by inserting a number of backslash-escaped special characters.

Display current BASH prompt (PS1)

Use echo command to display current BASH prompt:
$ echo $PS1Output:
[e]0;u@h: wa]${debian_chroot:+($debian_chroot)}u@h:w$
By default the command prompt is set to: [u@h W]$. Backslash-escaped special characters are decoded as follows:
  • u: Display the current username
  • h: Display the hostname
  • W: Print the current working directory

Task: Modify current BASH prompt

Use export command to setup a new shell prompt:$ export PS1="[\u@\H \W \@]\$"
  • H: Display FQDN hostname
  • @: Display current time in 12-hour am/pm format

Add colors to the prompt

To add colors to the shell prompt use the following export command syntax:
‘e[x;ym $PS1 e[m’
  • e[ Start color scheme
  • x;y Color pair to use (x;y)
  • $PS1 is your shell prompt
  • e[m Stop color scheme
To the prompt to blue, type the command:
$ export PS1="e[0;34m[u@h W]$ e[m "

Color codes

Color Code
Black 0;30
Blue 0;34
Green 0;32
Cyan 0;36
Red 0;31
Purple 0;35
Brown 0;33
Blue 0;34
Green 0;32
Cyan 0;36
Red 0;31
Purple 0;35
Brown 0;33
Replace digit 0 with 1 to get light color version.

How to make the prompt setting permanent

Your new shell prompt setting is temporary i.e. when you logout setting will be lost. To have it set everytime you login to your workstation add above export command to your .bash_profile file or .bashrc file.
$ cd
$ vi .bash_profile
$ vi .bashrc
Append export line:
export PS1="e[0;31m[u@h W]$ e[m"
Save and close the file.

tput command

You can also use tput command. For example display RED prompt use tput as follows:
export PS1="[$(tput setaf 1)]u@h:w $ [$(tput sgr0)]"

handy tput commands

  • tput bold – Bold effect
  • tput rev – Display inverse colors
  • tput sgr0 – Reset everything
  • tput setaf {CODE}- Set foreground color, see color {CODE} below
  • tput setab {CODE}- Set background color, see color {CODE} below

Colors {code} code for tput command

Color {code} Color
0 Black
1 Red
2 Green
3 Yellow
4 Blue
5 Magenta
6 Cyan
7 White
Read the man page of bash and tput command for more information.
Facebook Linux Marketing

Facebook Marketing 101

Check out this SlideShare Presentation:

Facebook Marketing

View more presentations from Neowave.
BackTrack Linux Ubuntu VMWare WEP WPA

Shutdown Command for BackTrack 3 or 4

Since BackTrack is built on Linux you can shutdown BackTrack from the shell using poweroff or restart it with reboot.

BackTrack links


Ultimate Tutorial on Where to Begin Hacking with Hacker’s Underground Handbook

The information in this underground handbook will put you into a hacker’s mindset and teach you all of the hacker’s secret ways: The Hacker’s Underground Handbook.
Learn hack now.

  • You will learn all the hackers underground tricks and learn to apply them in real world situations.
  • You will be put into a hackers mindset and learn to think like one.
  • By Learning how a hacker thinks and acts, you will be able to protect yourself from future hack attacks.
  • This Underground handbook may get you interested in pursuing a career as an Ethical
For a limited time only, with the purchase of The Hacker’s Underground Handbook you will receive this bonus package! 1000 Hacking Tutorials Leaked contains 1000 of the best hacking tutorials of 2009 leaked on the internet.

HostMonitor Linux Network Monitoring Networking Windows

Network Monitoring With Advanced Host Monitor by KS-Soft

HostMonitor is a highly scalable network monitoring software and it is suitable for small and enterprise-level networks.

You will progably say “There are dozens of programs like this“? That is right! But please check what HostMonitor offers and compare its power and flexibility to surprisingly low price:
  • using 62 test methods this software can check almost any parameter of your servers;
  • highly flexible action profiles allow you to start actions in predefined order depending on the test results;
  • HostMonitor creates various log files using different detail levels and file formats (Text, HTML, DBF and ODBC);
  • built-in Report Manager allows you to create and customize reports to your liking in a variety of ways;
  • using Remote Monitoring Agents for Windows, FreeBSD, Linux, NetBSD, OpenBSD and Solaris you may easily monitor remote networks;
  • Web Service, Telnet Service and Remote Control Console simplifies remote management;
  • and this is not all…  Advanced Host Monitor does much more!  
I have been using HostMonitor for years and love it.  It is flexible, easy to use and won’t break the bank.  Check it out.
iPhone iPod iTouch Linux Windows

How to type accented characters on iPhone and iPod Touch

If you find yourself needing to type an accented character (acutes, graves, umlauts, etc.), all you have to do is hold down the relevant key for a couple of seconds and voilà a nice pop-up menu will appear with the available choices. The trick works for a number of different characters besides the vowels (e.g. ‘z’ and ‘?’) and this works as well on the iPod touch.