Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I currently have PS1='\W' but when in a symbolic link'd directory, the prompt shows the symlink name, how can I make PS1 to show the original directory name?

share|improve this question
up vote 3 down vote accepted

On Linux, you can use the following:

export PS1='$( readlink -f . )'


$ export PS1='$( readlink -f . ) \$ '
/home/danielbeck $ ln -s /etc foo
/home/danielbeck $ cd foo
/etc $ _

Note that you still will be in /home/danielbeck/foo for everything else, like resolving parent directories with cd .., so, to continue the example:

/etc $ cd ..
/home/danielbeck $ _

Another option might be to replace cd with a function that enters the canonical directory instead of the symlink, something like:

function cd {
    if [[ $# -ne 1 ]] ; then
        builtin cd "$@"
    elif [[ "$1" = "-" ]] ; then
        builtin cd -
        builtin cd "$( readlink -f "$1" )"

This might also work for any cd arguments and supports even CDPATH:

function cd {
    builtin cd "$@"
    builtin cd "$( readlink -f . )"
share|improve this answer

You must log in to answer this question.

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