Pesquisar este blog

terça-feira, 24 de agosto de 2021

Prompt no linux

 export PS1="c:\>"

export PS1="\d-\u >"

export PS1="\d-\H >"   --> Hostname

export PS1="\u >\s\v " --> Versão

export PS1="\W > "



More BASH Prompt Options

Here is a list of most of the options you can use for the BASH prompt.

Some of these commands may not work on all versions of Linux.

  • \a – A bell character
  • \d – Date (day/month/date)
  • \D{format} – Use this to call the system to respond with the current time
  • \e – Escape character
  • \h – Hostname (short)
  • \H – Full hostname (domain name)
  • \j – Number of jobs being managed by the shell
  • \l – The basename of the shells terminal device
  • \n – New line
  • \r – Carriage return
  • \s – The name of the shell
  • \t – Time (hour:minute:second)
  • \@ – Time, 12-hour AM/PM
  • \A – Time, 24-hour, without seconds
  • \u – Current username
  • \v – BASH version
  • \V – Extra information about the BASH version
  • \w – Current working directory ($HOME is represented by ~)
  • \W – The basename of the working directory ($HOME is represented by ~)
  • \! – Lists this command’s number in the history
  • \# – This command’s command number
  • \$ – Specifies whether the user is root (#) or otherwise ($)
  • \\– Backslash
  • \[ – Start a sequence of non-displayed characters (useful if you want to add a command or instruction set to the prompt)
  • \] – Close or end a sequence of non-displayed characters


Use the following options to display different formats for date and time:

  • d – Displays today’s date in [weekday]/[month]/[day]
export PS1="\u@\H>\d "
  • t – Displays the current time in 24-hour notation
export PS1="\u@\H>\t "
  • T  Displays the current time in 12-hour notation
export PS1="\u@\H>\T "
  • A – Displays the current time in 24-hour notation, with just hours and minutes
export PS1="\u@\H>\A "

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 green, enter the following:

export PS1="\e[0;32m[\u@\h \W]\$ \e[0m"
Change the bash color in Linux

Your prompt should have the same text as normal but be colored green.

Here’s a breakdown of the commands:

• \e[ – Begin color changes
• 0;32m – Specify the color code
• [\u@\h \W]\$ – This is the code for your normal BASH prompt (username@hostname Workingdirectory $)
• \e[0m – Exit color-change mode

The first number in the color code specifies the typeface:

• 0 – Normal
• 1 – Bold (bright)
• 2 – Dim
• 4 – Underlined

The second number indicates the color you want:

• 30 – Black
• 31 – Red
• 32 – Green
• 33 – Brown
• 34 – Blue
• 35 – Purple
• 36 – Cyan
• 37 – Light gray

Additionally, if you combine the bright option with a color code, you get a lighter version of that color. For example, if you use color code 1;32, you would get light green instead of the normal green. If you use 1;33, you get yellow instead of 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 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:

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

Retirado de : https://phoenixnap.com/kb/change-bash-prompt-linuxEm 24/08/2021

Nenhum comentário:

Postar um comentário

Observação: somente um membro deste blog pode postar um comentário.