How to change the display name on the Terminal?
Solution 1
This actually displays your username@computername: along with the current directory and a $ sign, which usually means a non-root user, whereas a # sign would mean that you have root permissions.
Now, to only change what's displayed, you can edit your ~/.bashrc
file. Open it with your favorite text editor and make changes to the line that starts with PS1=
.
If you have more than one line starting with PS1=
, try changing them one by one, while saving the .bashrc
file and opening a new terminal each time, to see if you edited the right one.
To just experiment with what's displayed, without messing up anything, you can type export PS1="whatever you want"
. Once you close and reopen the terminal, it will set the value of PS1 back to the one in your ~/.bashrc
file.
To actually change your username or computer name, there are already excellent answers:
You will need to log out and log in again to see the changes, unless you're changing the name of your computer, for which you'll need to reboot the machine.
Solution 2
The first administrator is your username, and the second one is the name of the computer (hostname). You can make another account with different username and rename your computer, but I suspect you don't want to do that. You can put whatever you like in your prompt in the terminal. The following variable determine, what are you going to see as a prompt:
- PS1 – Default interactive prompt (this is the variable most often customized)
- PS2 – Continuation interactive prompt (when a long command is broken up with \ at the end of the line) default=">"
- PS3 – Prompt used by “select” loop inside a shell script
- PS4 – Prompt used when a shell script is executed in debug mode (“set -x” will turn this on) default ="++"
- PROMPT_COMMAND - If this variable is set and has a non-null value, then it will be executed just before the PS1 variable.
Take look here:
- http://ss64.com/bash/syntax-prompt.html
- https://www.maketecheasier.com/more-useful-and-interesting-bash-prompts/
- https://www.linux.com/learn/how-make-fancy-and-useful-bash-prompt-linux
- http://ezprompt.net/
- http://bashrcgenerator.com/
- http://www.thegeekstuff.com/2008/09/bash-shell-ps1-10-examples-to-make-your-linux-prompt-like-angelina-jolie/
Experiment with these variable and find out what you want :) For example:
export PS1="Hello.Master$ "
If you want your prompt changes to make permanent, you can put them in many places like:
- /etc/bash.bashrc
- ~/profile
Related videos on Youtube
Benjamin
Updated on September 18, 2022Comments
-
Benjamin over 1 year
When I open the terminal, the username and host name are displayed to the left of the typing area like this:
administrator@administrator:~$
What specific steps do I take to set custom values?
-
Zanna over 7 yearsDo you want to change only what is displayed in your prompt, or change the name of your user and of the computer? (That's what the prompt displays)
-
Admin over 7 yearsPossible duplicate of How do I change the computer name?
-
Sergiy Kolodyazhnyy over 7 yearsPossible duplicate of How can I shorten my command line (bash) prompt?
-
-
Zanna over 7 yearsAlso, there are at least 3 lines in .bashrc starting with PS1= and the reader can't tell from your post which one to edit, or how.
-
Brane over 7 yearsCan you give me an example? The PS1 variable may be used in some condtitional statements, but there's usually only one line that begins with
PS1=
. -
Zanna over 7 yearsI don't see how you can say it's fully answered unless you assume the OP understands all the codes used in PS1, and how the conditional statements (have a look, 3 lines start like that) work in
.bashrc
. I don't find guidance for this in your post... -
Brane over 7 yearsMy answer clearly states "a line that begins with PS1". I tried to provide a quick and easy answer. I welcome you to explain in depth how variables, conditional statements and colors work in bash/dash, but I doubt that's what the OP wanted answered.
-
Zanna over 7 yearsWell editing one of them at random has a 2/3 chance of having no effect at all ;) And without explanation, how will they get what they want ?(which is unclear from the question imo)
-
Brane over 7 yearsLet us continue this discussion in chat.
-
jlliagre over 7 yearsI would suggest export
PS1='Hello master $ '
instead as an example. -
Yash Kumar Verma over 4 yearshow to change it back to default ?