To show the entire directory path we can configure our terminal prompt like this:

export PS1="\w: "

That will show the entire directory path like this:


What if we only want to show the current directory and it's container like this:


Thoughts? I'm using the bash shell ...

2 Answers 2


I'm just going to throw this out there for the few ksh users on the Mac besides myself. I did not create this, I just use it.

# Discipline function for relative present working directory
# by Martijn Dekker <[email protected]> 2020-08-09; public domain
function _relative_pwd.get
    typeset del ellip=$'\u2026' v=$PWD keep=*/*   # add /* for each element to keep
    ((${#ellip}==1)) || ellip='...'
    [[ ($v == "$HOME" || $v == "$HOME"/*) && $HOME != / ]] && v=\~${v#"$HOME"}                                          
    [[ $v == /*/$keep ]] && v=$ellip/${v#"$del"}
    [[ $v == \~/*/$keep ]] && v=\~/$ellip/${v#"$del"}

And set PS1

$ PS1="\${_relative_pwd} $ "

Example resulting prompt...

~/…/ksh/arch $


Per the Unix StackExchange Link, this will do the trick (I'm using a bash shell):

vi ~/.bash_profile`

And add

export PS1='${PWD#"${PWD%/*/*}/"} \$ '

Then save and source ~/.bash_profile.

  • For an actual answer see this unix.stackexchange.com/a/217097/5140
    – mmmmmm
    Commented Jun 16, 2021 at 18:18
  • Yeah ... It only works initially ....
    – Ole
    Commented Jun 16, 2021 at 19:54
  • 1
    @Ole That works fine in ksh and bash. I'm not sure why it wouldn't work for you. I think my main objection to it would be that it doesn't give any indication of how deep you are. Don't ever export PS1, though. Commented Jun 17, 2021 at 5:24

You must log in to answer this question.

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