Shortening Username in Ubuntu Command Prompt


Most of the Ubuntu  users face this problem that is ” How to shorten the command prompt name in Ubuntu?” Because in the Linux command prompt the user name appears as a long text. Sometimes it will be uneasy for us to see that long name. And there become the need of the way to change the name. Here in this post i have added some useful information to shorten the command prompt name in Ubuntu. Guys check it out…….

METHOD 1:(PERMANENT CHANGE)

It is very simple method by using this you can make your user name short.

Simply try this code:

sudo nano /etc/hostname

A file appears and then change the name of the file.

NOTE: You have to reboot the system after changing the name in the file. Unless you reboot the system this will not work.

METHOD 2:(PERMANENT CHANGE)

Untitled

At first we have to alter the variable PS1 in the environment.

Because PS1 variable is responsible for the appearance of the command prompt.

Here i have given the short extract of the default .bashrc file in Ubuntu 10.04 LTS

Code:

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

Result: username@hostname:~/directory$

If you feel the hostname is still unnecessary then you can take the command \h which is host name.

Then you have to change the above code. And the changed code will look like the following code:

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u:\w\$ '
fi

Result:username:~/directory$

METHOD 3:(TEMPORARY CHANGE)

When we override the PS1 variable temporary username can be created.

Overriding should be done in your current sytem’s bash session.

Code:

export PS1="\u:\w\$ "

 

 

 

1:43 pm