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?

  • 2
    You should add what kind of shell your are using and how the prompt is configured in your .*rc file. Nov 24, 2015 at 11:13
  • Question updated. I am using default terminal settings of Fedora for learning. Also I notice this behavior in other places using Ubuntu.
    – Kenny
    Nov 24, 2015 at 13:09
  • Maybe depends with what user you are browsing through the directories? Nov 24, 2015 at 13:18
  • 1
    Could you add the output of: echo $PS1 ?
    – Jeff Schaller
    Nov 24, 2015 at 13:57

3 Answers 3


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
jackman@b7q9bw1:/usr/local/share/doc $ PROMPT_DIRTRIM=2
jackman@b7q9bw1:.../share/doc $ pwd
jackman@b7q9bw1:.../share/doc $ 

What is displayed in the primary prompt is decided by the contents of the PS1 variable. Here is an excerpt from the bash documentation:

\w     the current working  directory,  with  $HOME  abbreviated
       with  a tilde (uses the value of the PROMPT_DIRTRIM vari‐
\W     the basename of the current working directory, with $HOME
       abbreviated with a tilde

This means that if your PS1 uses \w, then the entire path for the current directory will be printed, whereas \W would cause the other behavior you observed: just the last component is displayed (with an exception, in both cases, for your home directory).

The default PS1 on some random Linux-based system I tried was [\u@\h \W]\$, but this varies from system to system.


This is a matter of what is in your PS1 variable. You can check your PS1 variable by executing echo $PS1.

If there is a \w, you see the full path, if there is a \W, you only see the last folder.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .