How can I shorten my command line (bash) prompt?

To change it for the current terminal instance only

Just enter PS1='\u:\W\$ ' and press enter.


To change it "permanently"

In your ~/.bashrc, find the following section:

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

Remove the @\h, and replace the \w with an uppercase \W, so that it becomes:

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

Save, exit, close terminal and start another to see the result.


Tons more options!

  • See here for a more extensive howto, with many more options
  • See this answer for using up a tiny Python script to set the prompt so that the shortening only occurs when you are deep in a directory structure.

Run this code in the current terminal

PROMPT_DIRTRIM=3

Now the bash prompt will show only the last 3 directory names. You can choose 1 to show only current directory. More information is available in the GNU documentation.

The effect:

/var/lib/apt/lists# PROMPT_DIRTRIM=3
/.../lib/apt/lists# 

If you want to make it permanently, add the following line to ~/.bashrc in the beginning:

PROMPT_DIRTRIM=3

or another number greater than zero.


This is my preferred prompt setting:

added in ~/.bashrc

PS1='[\u@\h \W]\$ '    

it looks like this:

[user@hostname dirname]$

(with a space after the $ sign)