Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

So everytime I change the directory I would like the new path to automatically get listed with ls.
There are solutions if the path gets changed using cd but I never found a solution that would work when the path gets changed using the autocd option.

Would be quite convenient, has anyone achieved that before?

share|improve this question
up vote 4 down vote accepted

You can achieve this by changing the variable PROMPT_COMMAND, which is executed before PS1, e.g.:


This will list each time you get a new prompt. Of course you only want to execute ls if the directory has changed:

PROMPT_COMMAND='[[ $my_currdir != $PWD ]] && ls; my_currdir=$PWD'

This checks if the new directory isn't the same as the last one set, and then executes ls, after which your current directory is stored in my_currdir

I found an even better line here, where they use bash as a file manager:

PROMPT_COMMAND='[[ ${__new_wd:=$PWD} != $PWD ]] && list; __new_wd=$PWD'

since it is possible that __new_wd is unset, you can assign a default value which will be used in that case (see bash man pages, search for :=)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.