Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

How to reduce the command line prefix length (i.e folder name or path in bash)?

For example:

venu@venupc:~$ cd Documents/Code/new/

I want to display present folder name new instead of complete path (venu@venupc: new$).

share|improve this question
superuser.com/questions/60555/… –  Rinzwind Jan 23 '14 at 11:20
None of the AU answers there point to the real solution, as the SU question does: use \W. So I vote to reopen the question. –  enzotib Jan 23 '14 at 12:00

1 Answer 1

Read man bash, the PROMPTING section, and about the PROMPT_DIRTRIM environment variable.

          If set to a number greater than zero, the value is used as the number of trail‐
          ing  directory  components to retain when expanding the \w and \W prompt string
          escapes (see PROMPTING below).  Characters removed are replaced with an  ellip‐

Add export PROMPT_DIRTRIM=1 to ~/.bashrc, and you'll get close to what you want.

share|improve this answer
Even after 'adding export PROMPT_TRIMDIR=1' to ~/.bashrc not solved the problem. I have added below line in the ~/.bashrc to solve the issue. export PS1='[\u@\h \W]\$ ' –  Venu Gatla Feb 12 '14 at 3:57
My mistake. The variable is really called PROMPT_DIRTRIM walt@squid:~/gsettings(0)$ cd /usr/bin/X11/X11/X11/X11 +walt@squid:/usr/bin/X11/X11/X11/X11(0)$ export PROMPT_DIRTRIM=1 +walt@squid:.../X11(0)$ walt@squid:.../X11(0)$ echo "$PS1" | cat -A ${debian_chroot:+($debian_chroot)}${SUBSHELL}\[\033[01;32m\]\u@\h\[\033[00m\]:\[‌​\033[01;34m\]\w\[\033[1;31m\]($?)\[\033[00m\]\$ $ +walt@squid:.../X11(0)$ –  waltinator Feb 15 '14 at 2:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.