View Directory List After Entering

When navigating the file structure in Unix/Linux environments you will often find yourself typing cd to change the directory and then immediately typing ls to see the contents of the directory.

It is possible to run ls automatically every time you run cd by adding the following commands to your .bashrc file.

cd() {
 if [ -n "$1" ]; then
  builtin cd "$@" && ls
 else
  builtin cd ~ && ls
 fi
}}

 

Comments

Thanks for this. I've been looking around for quite a bit trying to find this. I stumbled upon it a long time ago and lost it after a while.
Permalink

Add new comment

The content of this field is kept private and will not be shown publicly.