Skip to content

Instantly share code, notes, and snippets.

@vargeorge
Created September 4, 2014 20:45
Show Gist options
  • Save vargeorge/8b20488b7d7b6c101b4b to your computer and use it in GitHub Desktop.
Save vargeorge/8b20488b7d7b6c101b4b to your computer and use it in GitHub Desktop.
Show full path on OS X terminal / iTerm before the $ prompt
1. Edit ~/.bash_profile and add the following line to show full path before the $ prompt.
For example, as user@hostname:path/to/directory$
# show path before the $ prompt
export PS1='\u@\H:\w$ '
2. Save file and restart terminal or run source command
$ source ~/.bash_profile
@philiparthurmoore
Copy link

Works like a charm. Cheers.

@taulanthalili
Copy link

taulanthalili commented Sep 6, 2019

nice, thank you.
I used this, because of my long hostname : export PS1='\u@\h:\w$ '

@JasonWeakley
Copy link

Explanation of what this is doing:

  • '\u' is the username under which you are currently logged in to your computer.
  • '\h' is the host machine's name
  • '\w' is where you currently are in the file structure
  • '$' is the prompt symbol

So if you just want to know where you are and see the prompt you can edit your bash profile to be just '\w $' or concatenate them like '\w$'.

@mirisbowring
Copy link

On Big Sur it somehow prints the expression:

\u@\H:\w$

Never worked with zsh before. Does zsh use another config file than bash?

@KienPM
Copy link

KienPM commented Dec 30, 2020

On Big Sur it somehow prints the expression:

\u@\H:\w$

Never worked with zsh before. Does zsh use another config file than bash?

I have the same issue

@gnitsenko93
Copy link

@mirisbowring @KienPM I have faced the same issue.

I helped to me to switch to bash from zsh in system settings: https://stackoverflow.com/a/59439507

Also try (additionally, it is optional) to prompt exec bash and reload terminal.

@KienPM
Copy link

KienPM commented Jan 13, 2021

@mirisbowring @KienPM I have faced the same issue.

I helped to me to switch to bash from zsh in system settings: https://stackoverflow.com/a/59439507

Also try (additionally, it is optional) to prompt exec bash and reload terminal.

Thanks for responding

@AAwadallahAtypon
Copy link

On Big Sur it somehow prints the expression:

\u@\H:\w$

Never worked with zsh before. Does zsh use another config file than bash?

add PROMPT='%~ %n@%m:%# ' to ~/.zshrc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment