What Would You Enter at the Commanf Prompt to Start a Bourne Again Shell Session
Introduction
In Linux, much of your work occurs from a command prompt, besides known as the shell, or Bash (Bourne-Over again Shell). The crush interprets your commands and passes them to the operating system for execution.
This tutorial will evidence y'all how to customize or change your Linux BASH prompt.
Prerequisites
- A system running Linux
- Access to a command line/concluding
- A user account with sudo or root privileges
Default BASH Prompt
The default BASH prompt is the one you lot meet when you first open a last or command line. Information technology usually looks something like this:
[email protected]:~$
Alternatively, it may look like this:
(base) [[e-mail protected] ~]$
The first role of the prompt tells you lot the user that'southward currently logged in. The 2d office identifies the hostname of the system.
The tilde sign ~
indicates that the electric current working directory is the current user'due south home directory.
The dollar sign $
means the current user is a standard user.
A root user would exist identified with a hash sign #
.
Customize Bash Prompt In Linux
Like virtually Linux applications, Fustigate reads a configuration file to decide its beliefs. This file is in the home directory:
~/.bashrc
Before you make whatever changes, create a backup copy of your configuration file. Open a terminal window, and enter the following:
cp ~/.bashrc ~/.bashrc.bak
Note: The organization uses the .bak file extension to betoken a backup.
Change Bash Prompt in Linux Permanently
Open the Bash configuration file for editing:
sudo nano ~/.bashrc
In this file, yous should see several dissimilar 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> "
You can replace MyTestPrompt>
with any string of text you like.
Save the file ( ctrl-o
> Enter) and get out ( ctrl-x
).
Refresh the Fustigate service to use your changes. Enter the post-obit:
source ~/.bashrc
Your control-line prompt should modify to the following:
MyTestPrompt>
Note: Learn everything you need to know nigh working with Fustigate comments.
Create a Temporary Change to the Bash Prompt
You lot tin alter the Fustigate prompt temporarily by using the export
command. This command changes the prompt until the user logs out.
Set the BASH prompt to simply display the username by entering the following:
export PS1="\u >"
The prompt should immediately alter to look like this:
username >
Y'all can reset the prompt by logging out, and then logging back in.
Pop Custom Options for BASH Prompts
You can use these options in either method – temporarily with the export
command, or permanently by editing the ~/.bashrc
file.
Display Username and Domain Name
Use the –H
selection to display a a full hostname:
export PS1="\u\H "
You should see the hostname in the prompt.
Add Special Characters
You lot can add special characters to the prompt by placing them in order around the special options:
consign PS1="\[email protected]\H :"
This should display the following:
[e-mail protected]:
Annotation: We recommend ending the prompt with a special character or infinite. You should also place a infinite, colon, or angle-subclass just before the final quote marker. This method helps users tell the divergence between the prompt and the command they're typing.
Display Username Plus Shell Name and Version
Enter the post-obit to show username, beat proper name, and version:
export PS1="\u >\s\v "
The prompt should change to the following:
username >bash4.4
Add together Date and Time to The BASH Prompt
Use the post-obit options to display dissimilar formats for date and time:
-
d
– Displays today's date in [weekday]/[month]/[solar day]
consign PS1="\[electronic mail protected]\H>\d "
-
t
– Displays the current time in 24-hour annotation
export PS1="\[email protected]\H>\t "
-
T
– Displays the current time in 12-hr notation
export PS1="\[email protected]\H>\T "
-
A
– Displays the current time in 24-60 minutes notation, with just hours and minutes
export PS1="\[email protected]\H>\A "
Note: The \[email protected]\H options preceding the date and time option add the username and full domain name.
Hibernate All Information in the BASH Prompt
Use this to forestall usernames or hostnames from displaying at the prompt:
export PS1="\W > "
You should see the following:
~ >
Differentiate Root User From Normal User
The normal BASH prompt displays a $
sign for a normal user. If you lot log in as a root user, a #
sign is displayed. Utilise the $
code to signal that the current user is not a root user:
export PS1="\[email protected]\H \W:\$ "
More BASH Prompt Options
Here is a listing of nearly of the options y'all can utilize for the Bash prompt.
Some of these commands may non work on all versions of Linux.
-
\a
– A bell grapheme - \
d
– Date (day/calendar month/date) -
\D{format}
– Use this to telephone call the arrangement to respond with the electric current time -
\east
– Escape character -
\h
– Hostname (short) -
\H
– Full hostname (domain name) -
\j
– Number of jobs being managed by the crush -
\fifty
– The basename of the shells terminal device -
\n
– New line -
\r
– Wagon return -
\s
– The name of the shell -
\t
– Time (60 minutes:minute:second) -
\@
– Fourth dimension, 12-hr AM/PM -
\A
– Time, 24-hour, without seconds -
\u
– Electric current username -
\v
– BASH version -
\V
– Extra data about the Fustigate version -
\w
– Electric current working directory ($HOME is represented by ~) -
\Westward
– The basename of the working directory ($HOME is represented by ~) -
\!
– Lists this command'due south number in the history -
\#
– This command's control number - \
$
– Specifies whether the user is root (#) or otherwise ($) - \\– Backslash
-
\[
– Get-go a sequence of non-displayed characters (useful if y'all desire to add a command or instruction set up to the prompt) -
\]
– Close or end a sequence of non-displayed characters
How to Change BASH Prompt Color
You can change the text color of your BASH prompt. For example, to temporarily change the text of your Bash prompt to dark-green, enter the following:
export PS1="\e[0;32m[\[email protected]\h \West]\$ \e[0m"
Your prompt should take the same text as normal but be colored greenish.
Here'southward a breakdown of the commands:
• \e[
– Begin color changes
• 0;32m
– Specify the colour lawmaking
• [\[e-mail protected]\h \W]\$
– This is the code for your normal Bash prompt ([e-mail protected] Workingdirectory $
)
• \e[0m
– Go out colour-change way
The offset number in the color code specifies the typeface:
• 0
– Normal
• 1
– Bold (bright)
• two
– Dim
• 4
– Underlined
The second number indicates the color you want:
• xxx
– Blackness
• 31
– Ruby-red
• 32
– Green
• 33
– Brown
• 34
– Blueish
• 35
– Regal
• 36
– Cyan
• 37
– Calorie-free grayness
Additionally, if you combine the vivid choice with a color code, you become a lighter version of that colour. For example, if you use color code 1;32
, you would go light green instead of the normal green. If you employ 1;33
, y'all become yellow instead of chocolate-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), yous can reset the default by logging out.
If you edited the \.bashrc
file to make permanent changes, there are two methods to revert to default settings:
- Return your changes equally comments by editing the file and calculation a
#
before each modify you made. - Restore default settings from your fill-in by entering:
sudo cp ~/.bashrc.bak ~/.bashrc
Understanding Dissimilar Parts of Fustigate Prompt
Before you continue, reset your Fustigate prompt to the default. If you used the consign
command, log out and log back in. If you edited your ~/.bashrc
file, place a #
sign before each edit y'all made and save the file.
The Bash prompt contains four different values: PS1, PS2, PS3, and PS4.
The PS stands for Prompt Argument. Then far, we've been working with the PS1 value. To run into the current PS1 value, enter the following:
echo $PS1
Depending on the system, the concluding returns something like this for the default settings:
You might recognize the \[email protected]\h
options equally the username and host. The westward
choice displays the electric current working directory.
Now, brandish the PS2 value:
echo $PS2
The organization should display simply an angle-bracket:
>
Repeating the aforementioned command for PS3 should be bare.
For PS4, you'll run across a +
sign.
Here are the different meanings for the different parts of the BASH prompt:
- PS1 – This is the principal prompt display. This is where yous set special characters or important data.
- PS2 – This is the secondary prompt string. This is unremarkably gear up equally a divider between the prompt display and the text entry. It is also used to display when a long control is broken into sections with the \ sign.
- PS3 – This is the prompt for the
select
control. - PS4 – This is the prompt for running a shell script in debug mode.
Under most circumstances, you'll exist working with just the PS1 option and mayhap the PS2 selection equally well.
Conclusion
You should now be able to customize your BASH prompt. You can combine the commands and options to get the expect and feel you want.
Every time you start a shell session in Linux, the system goes through configuration files and sets up the environment accordingly. Check out our guide on how to set, view, and unset environment variables in Linux.
Next, Vim users may desire to customize Vim and apply custom color schemes.
Was this commodity helpful?
Yeah No
lairdfultentreske.blogspot.com
Source: https://phoenixnap.com/kb/change-bash-prompt-linux
0 Response to "What Would You Enter at the Commanf Prompt to Start a Bourne Again Shell Session"
Post a Comment