In Ubuntu (and other Linux systems), the command line prompt is automatically set by the system when the OS is installed. But that doesn't mean you can't change it. In fact, many users tweak the prompt as per their preference.

In this tutorial, we will discuss multiple ways in which you can change your Ubuntu system's command line prompt. Please note that all commands and instructions mentioned in this article have been tested on Ubuntu 14.04LTS.

How to customize command line prompt

To change the prompt, you can run the following command:

PS1="[any-text-here]"

For example, I executed the following command:

PS1="him:$ "

Here's the screenshot of the new prompt:

prompt-ps-example

In case you just want to quickly shorten the prompt, you can run the following command:

PS1='\u:\W\$ '

Here's an example of the aforementioned command:

prompt-ps-shorten

In case you want, you can specifically change the text after @ in the prompt. This can be done using the hostname command. Here's how the command needs to be executed:

sudo hostname [new-name]

For example, I executed the following command:

sudo hostname him-desk

And my prompt changed from:

prompt-previous

to:

prompt-new

Note that all the methods that have been described here let you change the prompt temporarily. For permanent changes, you need to tweak your .bashrc file - more on that here.

Leave a Reply

Your email address will not be published. Required fields are marked *

*