View Directory List After Entering

11 April, 2008 | Unix/Linux

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
}

Write a comment