How To Customize the Prompt
Most Linux systems when you open a terminal line have a default prompt in one color (usually gray) that tells you your user name, the name of the machine you're working on by default.
The prompt can show all types of information such as : time, date, load,number of users, etc...
The prompt is defined in the variable called "PS1", to see how you actual prompt code looks like do this command :
bash:> echo $PS1- so this bunch of signs,lines and numbers are the code that will output the content of you prompt line .
How can i alter or change my Prompt in Linux ?
-well, remember out variables tutorial and all that stuff is time to use all that .
- so now let's alter the PS1 variable so we can change our prompt look;
-nice you see that we have used the "export" command to overwrite the value of PS1 variable.
Note -this change will be available until we close this session.
How can i alter or change my Prompt in Linux permanently
-remember our .bashrc file ? So he is the answer to our question.
Let's go and edit this file to out needs:
Look of the .bashrc file and open it with any text editor you have:
Look inside this file the line "title to user@host" and alter the content of the PS1 variable , put what ever you want.
Note-if you are new to Linux make sure you save the string you are about to alter, so you can go back to it anytime you want.
After you have altered and saved the altered .bashrc file do the source ~/.bashrc command so that the changed should be applied.
And there you go your prompt has a new look.
Prompt creating command options
Color Codes Options
Examples of how we can alter the Linux Prompt
1-Show just the name of the user and the host name:
- this will show the following:
2-Show host name and the actual working directory:
- this will show the folowing:
3-Show hostname and time :
- this will show the following:
4-Show the prompt with a different color then grey:
This can be difficult to understand but i will put it in a easy way for you guys:
Creating a PS1 values with colors has a certain syntax and order:
Syntax
bash:> PS1="e[ color code you want and what ever you want to be displayed(host,time,user,etc..) e[m You can add more option, but it will be displayed with the default color "