Home > Uncategorized > Modify Your Command Prompt

Modify Your Command Prompt

You may find that you want to modify the prompt. This can help you create visibility for special features or just modify it to something more useful. You can view the default settings for the prompt by using this command:

echo $PS1

As stated above it will show user, hostname, location and definition whether it is a normal user or root.

Create a single character

PS1=”$ ”

The space behind the $ is enforced by placing the quotes so it does not run into your text. The $ is typically used to show that it is a normal user not the root user indicated by the “#”.

Change options for the prompt

\d : the date Weekday Month Date format
\h : the hostname up to the first ‘.’
\A : the current time in 24-hour HH:MM format
\u : the username of the current user
\w : the current working directory, with $HOME abbreviated with a tilde
\$ : if the effective UID is 0, a #, otherwise a $


Create a colored prompt

You may want to create a color prompt that you can use for visibility. In this example the hostname has been dropped to make a shorter prompt and the prompt is turned red but the commands that you enter will be black. The export command will change these features.

mike@ub:~$ export PS1=’\e[0;31m[\u:\w]\$ \e[m ‘
[mike:~]$

This will color the prompt but not any commands that you enter.

List of 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 for a lighter color.

Make Changes permanent
All of the changes you make will be lost when you close the terminal or log out. Here are directions to make them permanent.

Ubuntu
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_colored_prompt=yes

The .bashrc file in each user’s home directory allows you to change the default for the prompt to a color prompt by uncommenting the line:

#force_colored_prompt=yes

Unfortunately a typo in the line must also be corrected so that it should read:
force_color_prompt=yes

Ubuntu or CentOS
Place your custom prompt in the user .bashrc file with this command:

export PS1=’\e[0;31m[\u:\w]\$ \e[m ‘

About these ads
  1. No comments yet.
  1. No trackbacks yet.

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

Follow

Get every new post delivered to your Inbox.

Join 56 other followers

%d bloggers like this: