8

I'm new to Ubuntu 14.10, and I want to change the 'your name' (appear at the time of Installation) from hanu to Hanu in Terminal, i.e., hanu@4268 to Hanu@4268.

Eliah Kagan
  • 116,445
  • 54
  • 318
  • 493
  • possible duplicate of [How do I change the computer name?](http://askubuntu.com/questions/9540/how-do-i-change-the-computer-name) – mikewhatever Apr 13 '15 at 14:34
  • 7
    I think OP wants to change his username not the hostname. – Arronical Apr 13 '15 at 14:35
  • 1
    possible duplicate of [Using capitals in my username?](http://askubuntu.com/questions/19455/using-capitals-in-my-username) – NGRhodes Apr 13 '15 at 14:37
  • 5
    None of the two, he wants to change how its username *it's displayed* within the terminal, not to change his *actual* host name or his *actual* username. – kos Apr 13 '15 at 14:57

1 Answers1

17

You can accomplish this using a case modification parameter expansion of $USER instead of \u inside the PS1 environment variable. The expansion would be ${USER^} to uppercase only the first letter of the username).

You can run this variable assignment on the terminal to see the effect:

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

If do you want to make this change permanent, you can use this method:

  1. Edit the .bashrc file in your home folder
  2. Locate these lines:

    if [ "$color_prompt" = yes ]; then
        PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
    else
        PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
    fi
    
  3. In the two lines that begin with PS1=, replace \u by ${USER^}, so it looks like this:

    if [ "$color_prompt" = yes ]; then
        PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]${USER^}@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
    else
        PS1='${debian_chroot:+($debian_chroot)}${USER^}@\h:\w\$ '
    fi
    
0x2b3bfa0
  • 8,620
  • 5
  • 38
  • 59