Score:4

How to change my user or computer name which appeares before each command in the terminal window?

io flag

Is there any way to change the name which appears before every command line in the terminal window? If so, then how? As shown below, my current one is way too long and takes up a lot of space in each line.

$: command not found
liam@liam-Lenovo-Legion-Y7000:~$
ar flag
Welcome to Ask Ubuntu. Please don't put screenshots of the terminal. Always copy the text from the terminal and paste it directly in your question. Then format the pasted text as `code` by using the {_} icon above the edit question window. Please [edit your question](https://askubuntu.com/posts/1470880/edit) and indicate if you just want to change what is displayed on the terminal or you want to change your username? Changing your username may affect other things such as your "Home" folder `/home/liam` to `/home/harry`.
hr flag
The long part **after** the `@` symbol is your computer's *hostname* not your username. See for example [Change computer name Ubuntu](https://askubuntu.com/questions/1178486/change-computer-name-ubuntu)
ar flag
Open a terminal and copy and paste this command: `PS1='${debian_chroot:+($debian_chroot)}Harry@MyPC:\w\$ '` This will change your name to Harry and your computer's name to MyPC, but only temporarily and only as shown in the command prompt. Alternately you may change your computer's name to something short and simple like (Mercedes) "Benz" rather than "liam-Lenovo-Legion-Y7000".
oldfred avatar
cn flag
Because I have multiple installs and a couple of systems, I like to have short name for system & version. "fred@Z170-jammy:~$ "
sa flag
It may not be clear, especially to people new to Unix, but that prompt is extremely useful, not just for knowing which userid and system you are currently using, but for commands like scp and rsync to quickly move files and directories around. For example: ` $ scp ~/.bash_aliases joe@romulus: ` or `$ rsync -avz ~/.bash* joe@romulus: ` These will copy the files matched by the glob pattern to the userid "joe" HOME on romulus.
Score:4
bo flag

The long part is the computer name, also known as your host name: liam-Lenovo-Legion-Y7000

The easiest way would be to change your computer name to something like liam so that the prompt would appear like this:

liam@liam:~$

See this duplicate answer for how to change your computer name using the hostnamectl command.

In your case and to change your host name to liam, you could use the following command:

sudo hostnamectl set-hostname liam

Here is another duplicate question for how to change your device-name.


Alternatively, the following is a more complicated method that removes the computer name from your prompt.

Without changing the actual computer name, you can remove the computer name from the prompt by editing your ~/.bashrc file.

Before we begin, make a backup of this file:

cp ~/.bashrc ~/.bashrcbackup

Run the following command to use nano to edit the file:

nano ~/.bashrc

1. Press CTRL+W to search and then type PS1 and then press ENTER.

The line should look like this:

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

Edit the line to remove @\h\[\033[00m\] up to the : but do not remove the : so the edited line should look like this:

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u:\[\033[01;34m\]\w\[\033[00m\]\$ '

2. Press CTRL+W and then press ENTER.

This line should look like this:

PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '

Edit the line to remove @\h so the edited line should look like this:

PS1='${debian_chroot:+($debian_chroot)}\u:\w\$ '

3. Press CTRL+W and then press ENTER.

This line should look like this:

PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"

Edit the line to remove @\h so the edited line should look like this:

PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u: \w\a\]$PS1"

When you are done editing the file, press CTRL+o to save the changes and then press CTRL+x to exit nano.

Finally, run the following command to apply the changes:

source ~/.bashrc

Your prompt should now appear as the following:

liam:~$
Will avatar
id flag
The only other thing I’d suggest to this great answer is that you can experiment freely in a terminal - just type `PS1=<whatever you want to try out > ` and it will have immediate effect - like it and you can edit into .bashrc as above, and if you don’t like it, the changes disappear as soon as you close that terminal.
liam avatar
io flag
This just solved my proplem , thank you very much !
Score:1
it flag

Most of the length of your prompt is your hostname (too long for me to retype - one of the disadvantages of posting pictures of text, rather than posting formatted text. Please read https://askubuntu.com/help/how-to-ask and https://askubuntu.com/help/formatting .). Can you shorten the hostname?

The prompt is produced through shell magic, using the PS1 through PS4 environment variables, This magic is explained in man $SHELL, the "PROMPTING" section.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.