How to Remove User and Hostname in Terminal Prompt [Quick Geek Tricks]

terminal-prompt-featured

For Linux (or Mac) users who use the Terminal, you will find that the default prompt will come with the format [username@hostname ~]$. For example, on my Dell laptop the bash prompt will show [damien@damien-dell ~]$, where “damien” is my username, and “damien-dell” is the hostname. Let it be noted that this is only the default settings, and you are free to change it and have it display anything you want, or even remove it altogether.

The following steps show how to do that.

1. In your file manager press Ctrl + H to show hidden files.

2. Open the “.bashrc” file in a text editor.

file-manager-bashrc-file

3. Find the line that starts with PS1=. The complete line should be something like this: PS1='[\u@\h \W]\$ ' where \u represents the username, \h the hostname and \W your location in the file structure.

bashrc-ps1-line

4. To remove the username and hostname from the prompt, simply remove the \u@\h part so it looks like this: PS1='[\W]\$ '.

terminal-prompt-no-username-hostname

5. For pure minimalism, you can remove everything and just leave the prompt sign: PS1='\$ '.

terminal-prompt-removed-everything

6. Once you are done with the edit, save the file.

Now relaunch your terminal, and the changes will be reflected immediately. If you are not able to restart the terminal because of a running session, type source ~/.bashrc instead.

It’s that simple.

2 comments

  1. If you are going to change the prompt make it something useful
    PS1=’\e[32m\e[40m $MY_ENV_SETTING@\h\e[36m\e[1m\e[40m \u Last rc=$? \T \w\e[0m\n \$> ‘

    This gives me, colorized to my liking, my current environment; host; user name ; last status code ;time ; working dir on the next lime

Leave a Comment

Yeah! You've decided to leave a comment. That's fantastic! Check out our comment policy here. Let's have a personal and meaningful conversation.

Sponsored Stories