Sunday, 26 May 2019

How to remove computer name from prompt in Ubuntu terminal


If you are using Ubuntu terminal you must have noticed that terminal prompt looks like below -

Notice that prompt looks like -


The problem is this is fairly large and with more folders inside the root directory, there is much less space to type actual commands. In this post, I will show how to fix this.

How to remove computer name from prompt in Ubuntu terminal

To fix this you need to edit ~/.bashrc file. In this file there is a variable called PS1 that governs how your command prompt looks like. If you open ~/.bashrc you should see something like below -

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

# If this is an xterm set the title to user@host:dir
case "$TERM" in
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"

Let me explain a little bit about PS1 variable and above itself.

  • debian_chroot: This is applicable if you are running chroot operation (Your root directory is different than the default one). If you do not know chroot then do not worry, this is just and empty variable and can be ignored for now. 
  • XTERM: This is for a terminal emulator. If you are using XTERM PS1 under this would take effect.
  • color_prompt: This would be the default case for most. Your terminal would support color prompt. So PS1 under "$color_prompt" = yes is something you need to edit. 
If you have not heard above, don't worry about it just change the PS1 variable under the color_propmt if statement.

  • \u: expands to the current username
  • \h: expands to the current hostname
  • \w: expands to the current working directory
  • \$: expands to # for root and $ for all other users

Now that you know what each means and once you have figured out which PS1 to change you can simply remove "@\h" from it.

So change

if [ "$color_prompt" = yes ]; then

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


if [ "$color_prompt" = yes ]; then

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

Once done save it, and run -

  • source ~/.bashrc
or simply open a new terminal and you should see the change.

Related Links

Customizing tray/taskbar date display in Ubuntu to show the actual date


In my Ubuntu 18.04.2 LTS, I see that the date/time displayed on the desktop on the taskbar above is like - "Sun 12.00 PM".


You have to actually click on it to see the current date. In this post, I will show you how to add a date to the format that you see on the top. It would have been much easier if Ubuntu gave us this customization in settings itself, but unfortunately, that is not the case, at least not yet.

Customizing tray/taskbar date display in Ubuntu to show the actual date

There are two ways you can do this. I will show the most user-friendly method first.  But if you are more comfortable with Linux command line terminal and executing commands go to 2. advance section below.

1. User-Friendly - GUI Way

If you do not prefer using the command line, then you can install a GUI based tool. The tool name is "gnome-tweak-tool". You can search for "GNOME tweaks" in the Ubuntu software center. Install it.

Launch it and you should see the following screen. Go to Top Bar for date settings.

You can change the configuration as needed. You can see there are a bunch of other options here as well - like show battery percentage. All yours to play with :)

NOTE: If you do not prefer the Ubuntu software center but apt-get to install software, you can use the following command to install and launch the above application.

sudo apt install gnome-tweak-tool
gnome-tweaks  #  now launch it

2. Advanced - CLI Way

There are two commands that you need to know here -
  1. gsettings set org.gnome.desktop.interface clock-show-date true
    • makes the date appear
  2. gsettings set org.gnome.desktop.interface clock-show-seconds true
    • switches the seconds display on
You can similarly replace "set" by "get" to see the current values. By default, both values are set to false which is why you don't see a date or seconds.

Now let's go ahead and set these values to true and see the change of date/time format in the taskbar above.

And the result is -

I personally don't like seconds showing up. Just date works for me, so I have set accordingly. You can have settings that best suit you. You can do a similar thing with battery percentage as well with following command -

  • gsettings set org.gnome.desktop.interface show-battery-percentage true

Related Links

t> UA-39527780-1 back to top