Bash – Current directory abbreviation rule in shell prompt

bashpromptworking directory

Sometimes I see that the current working directory in shell prompt is abbreviated and sometimes not.

For example /usr/bin will be displayed as bin$ or /folder1/folder2 displayed as folder2$, in other cases I have seen /folder1/folder2 displayed as full /folder1/folder2$

I am using default terminal settings (I am using Fedora 22 virtual machine for learning, but I also notice this fact in several other tutorial videos using different distro)

Is there any rule?

Best Answer

Another way to shorten the path, if you use \w is with the PROMPT_DIRTRIM shell variable. A demo:

jackman@b7q9bw1:/usr/local/share/doc $ echo "$PS1"
\u@\h:\w \$ 
jackman@b7q9bw1:/usr/local/share/doc $ pwd
/usr/local/share/doc
jackman@b7q9bw1:/usr/local/share/doc $ PROMPT_DIRTRIM=2
jackman@b7q9bw1:.../share/doc $ pwd
/usr/local/share/doc
jackman@b7q9bw1:.../share/doc $