12. what symbol displays in the shell prompt to indicate the logged-on user is root in linux?

Introduction

In Linux, much of your work occurs from a control prompt, also known equally the crush, or BASH (Bourne-Once again Shell). The beat interprets your commands and passes them to the operating arrangement for execution.

This tutorial will testify you how to customize or change your Linux BASH prompt.

tutorial on customizing the Linux Bash Prompt

Prerequisites

  • A arrangement running Linux
  • Access to a command line/concluding
  • A user account with sudo or root privileges

Default Fustigate Prompt

The default Bash prompt is the one you see when you lot first open a last or control line. Information technology commonly looks something similar this:

          [email protected]:~$        

Alternatively, information technology may look similar this:

          (base) [[e-mail protected] ~]$        

The showtime part of the prompt tells yous the user that'southward currently logged in. The 2nd role identifies the hostname of the system.

The tilde sign ~ indicates that the current working directory is the current user's home directory.

The dollar sign $ means the electric current user is a standard user.

A root user would be identified with a hash sign # .

Customize Fustigate Prompt In Linux

Like near Linux applications, BASH reads a configuration file to determine its beliefs. This file is in the abode directory:

          ~/.bashrc        

Earlier yous make any changes, create a backup copy of your configuration file. Open a terminal window, and enter the following:

          cp ~/.bashrc ~/.bashrc.bak        

Annotation: The organisation uses the .bak file extension to signal a backup.

Change Bash Prompt in Linux Permanently

Open the Fustigate configuration file for editing:

          sudo nano ~/.bashrc        

In this file, you should see several unlike settings. Some of them are descriptive lines in blue, uncommented with a # sign. Some are white, which indicates that they are enabled.

Scroll to the lesser of the configuration file. Add the following line:

          PS1="MyTestPrompt> "        
Edit bashrc file to change BASH appearance.

Yous can replace MyTestPrompt> with any string of text you like.

Salve the file ( ctrl-o > Enter) and leave ( ctrl-ten ).

Refresh the BASH service to apply your changes. Enter the following:

          source ~/.bashrc        

Your command-line prompt should change to the following:

          MyTestPrompt>        
The appearance of BASH prompt after changing bashrc configuration file.

Note: Learn everything yous demand to know about working with Fustigate comments.

Create a Temporary Change to the BASH Prompt

You lot can change the Fustigate prompt temporarily by using the export command. This control changes the prompt until the user logs out.

Set up the BASH prompt to only display the username by inbound the following:

          export PS1="\u >"        

The prompt should immediately modify to look like this:

          username >        
The command to show only your username in the bash prompt.

You can reset the prompt by logging out, then logging back in.

Popular Custom Options for BASH Prompts

Y'all tin use these options in either method – temporarily with the export command, or permanently by editing the ~/.bashrc file.

Display Username and Domain Name

Employ the –H pick to display a a total hostname:

          consign PS1="\u\H "        

You should come across the hostname in the prompt.

Show full hostname in Linux BASH

Add together Special Characters

Yous can add special characters to the prompt by placing them in order effectually the special options:

          consign PS1="\[email protected]\H :"        

This should brandish the following:

          [email protected]:        

Annotation: We recommend ending the prompt with a special character or space. You should besides place a space, colon, or angle-subclass just earlier the concluding quote mark. This method helps users tell the deviation between the prompt and the control they're typing.

Display Username Plus Shell Name and Version

Enter the following to show username, vanquish name, and version:

          export PS1="\u >\southward\5 "        

The prompt should change to the post-obit:

          username >bash4.4        
Show username and bash version in the terminal

Add Date and Time to The BASH Prompt

Utilise the following options to display dissimilar formats for date and time:

  • d Displays today'south date in [weekday]/[month]/[day]
          export PS1="\[email protected]\H>\d "        
  • t Displays the current fourth dimension in 24-hour notation
          export PS1="\[e-mail protected]\H>\t "        
  • T Displays the current time in 12-hour notation
          export PS1="\[electronic mail protected]\H>\T "        
  • A Displays the current time in 24-hour notation, with just hours and minutes
          consign PS1="\[electronic mail protected]\H>\A "        

Note: The \[electronic mail protected]\H options preceding the date and time option add the username and full domain name.

Hibernate All Data in the Bash Prompt

Apply this to prevent usernames or hostnames from displaying at the prompt:

          export PS1="\W > "        

You lot should see the following:

          ~ >        

Differentiate Root User From Normal User

The normal Fustigate prompt displays a $ sign for a normal user. If you log in as a root user, a # sign is displayed. Utilise the $ code to signal that the electric current user is not a root user:

          export PS1="\[email protected]\H \West:\$ "        

More than Bash Prompt Options

Hither is a list of virtually of the options you lot can utilize for the BASH prompt.

Some of these commands may non piece of work on all versions of Linux.

  • \a – A bell graphic symbol
  • \d – Date (mean solar day/month/engagement)
  • \D{format} – Employ this to call the system to reply with the current time
  • \e – Escape character
  • \h – Hostname (short)
  • \H – Full hostname (domain proper name)
  • \j – Number of jobs being managed by the vanquish
  • \l – The basename of the shells terminal device
  • \north – New line
  • \r – Carriage return
  • \southward – The name of the beat out
  • \t – Time (hr:minute:second)
  • \@ – Fourth dimension, 12-hr AM/PM
  • \A – Time, 24-hour, without seconds
  • \u – Current username
  • \5 – Bash version
  • \Five – Extra data nigh the Bash version
  • \westward – Electric current working directory ($HOME is represented by ~)
  • \W – The basename of the working directory ($HOME is represented by ~)
  • \! – Lists this command'due south number in the history
  • \# – This command's command number
  • \$ – Specifies whether the user is root (#) or otherwise ($)
  • \\– Backslash
  • \[ – Get-go a sequence of non-displayed characters (useful if you desire to add a command or instruction set to the prompt)
  • \] – Close or end a sequence of non-displayed characters

How to Change BASH Prompt Color

You tin change the text color of your Fustigate prompt. For example, to temporarily change the text of your BASH prompt to dark-green, enter the following:

          consign PS1="\eastward[0;32m[\[email protected]\h \West]\$ \e[0m"        
Change the bash color in Linux

Your prompt should accept the same text as normal merely be colored green.

Here's a breakdown of the commands:

\e[ – Begin color changes
0;32m – Specify the color code
[\[email protected]\h \W]\$ – This is the code for your normal BASH prompt ([electronic mail protected] Workingdirectory $)
\e[0m – Leave color-change mode

The showtime number in the color code specifies the typeface:

0 – Normal
i – Assuming (bright)
two – Dim
4 – Underlined

The second number indicates the colour y'all want:

30 – Black
31 – Red
32 – Green
33 – Brown
34 – Bluish
35 – Purple
36 – Cyan
37 – Low-cal grayness

Additionally, if you combine the bright option with a color code, you go a lighter version of that color. For example, if yous utilise color code 1;32 , you would get light dark-green instead of the normal light-green. If you use 1;33 , y'all go xanthous instead of dark-brown.

How to Reset BASH Changes to Default Settings

There are two ways to reset the changes. For temporary changes (using the export PS1="" command), you tin can reset the default by logging out.

If you lot edited the \.bashrc file to make permanent changes, there are ii methods to revert to default settings:

  • Render your changes as comments by editing the file and adding a # before each modify you made.
  • Restore default settings from your backup by inbound:
          sudo cp ~/.bashrc.bak ~/.bashrc        

Agreement Unlike Parts of BASH Prompt

Earlier you go on, reset your BASH prompt to the default. If you used the export command, log out and log back in. If y'all edited your ~/.bashrc file, place a # sign before each edit you made and salve the file.

The BASH prompt contains 4 different values: PS1, PS2, PS3, and PS4.

The PS stands for Prompt Statement. So far, we've been working with the PS1 value. To meet the current PS1 value, enter the following:

          echo $PS1        

Depending on the arrangement, the final returns something like this for the default settings:

The output of the echo $PS1 command in the terminal


You might recognize the \[e-mail protected]\h options as the username and host. The w pick displays the current working directory.

Now, display the PS2 value:

          repeat $PS2        

The organization should brandish just an angle-subclass:

          >        

Repeating the same command for PS3 should be blank.

For PS4, you'll meet a + sign.

Here are the dissimilar meanings for the different parts of the BASH prompt:

  • PS1 – This is the primary prompt display. This is where you set special characters or important information.
  • PS2 – This is the secondary prompt string. This is usually set every bit a divider between the prompt display and the text entry. It is also used to display when a long command is cleaved into sections with the \ sign.
  • PS3 – This is the prompt for the select command.
  • PS4 – This is the prompt for running a shell script in debug way.

Under about circumstances, you'll exist working with just the PS1 selection and possibly the PS2 selection too.

Conclusion

You should at present be able to customize your Fustigate prompt. You tin combine the commands and options to become the expect and feel you want.

Every fourth dimension yous kickoff a shell session in Linux, the system goes through configuration files and sets up the surroundings accordingly. Bank check out our guide on how to set, view, and unset environs variables in Linux.

Next, Vim users may desire to customize Vim and apply custom color schemes.

Was this commodity helpful?

Yes No

pirkleadame1937.blogspot.com

Source: https://phoenixnap.com/kb/change-bash-prompt-linux

0 Response to "12. what symbol displays in the shell prompt to indicate the logged-on user is root in linux?"

إرسال تعليق

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel