How to shorten the no of characters display for the current directory in the prompt

Solution 1:

You can use \W (capital "W") which will make your home directory (/home/username) display as a tilde ('~') and only show the basename of the current directory. So an example might look like:

dir:509:9$ pwd
/home/username/dir
dir:510:10$ cd ..
~:511:11$ 

If you're using Bash 4, you can set the PROMPT_DIRTRIM shell variable to a number of trailing directory levels to display. But there was a bug in it which was fixed in a maintenance release (4.1, I think).