Command Prompts in Unix and Linux Operating systems

Command Prompts in Unix and Linux Operating systems.

 

Command Prompt is a built-in feature in computers that allows users to interact with their operating system through a command-line interface.  Command Prompt allows users to execute commands, run scripts, navigate through directories, manage files and folders, and perform various other system operations.

 

Various Command prompts

$ prompt —> It is Default for normal user accounts that use Bourne,korn   in Unix and Linux.

# prompt —>It is Default for Super user accounts that use bourne,korn ,bash shells  in Unix and Linux.

% prompt —> It is Default for normal user accounts that use c-shell   in Unix and Linux.

For Bash shell , default value in PS1 environment variable is [\u@\h \W]\$

where as “u” is the username

“h” is the host IP

“W” is the working directory

For example : [ec2-user@ip-172-31-83-99 ~]$

~ (tilde) is the meaning for home directory.

 

How to customize the command prompts in Unix/ Linux ?

By using PS1 Environment Variable we can change the default prompt.

SPS1=”Test Server>”

echo $PS1

for example :

[ec2-user@ip-172-31-83-99 ~]$ PS1=”Test Server>”
Test Server>

To make this change permanently , add the above entry in .profile for Bourne and Korn shells. For  bash add the entry in .bash_profile.

From Next time onwards when it is restarted the entry shown above will be executed and your desired command prompt will be display .

 

Why we need to customize the prompt?

 

Command prompt can avoid human errors. For example , we have Test  and production servers and we need to run some commands that will cause outage on that particular server , by customizing the prompt we can differentiate which server is test and Prod . For example ,

  • TEST Server>
  • PROD Server>
  • DR Server>

Customizing the command prompt can make your experience using it more efficient and personalized.

By customizing the command prompt, you can modify the colors, fonts, and layout to enhance readability and make it more visually appealing.

 

See also: