View Directory List After Entering

11th April 2008

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.

  1. cd() {
  2. if [ -n "$1" ]; then
  3. builtin cd "[email protected]" && ls
  4. else
  5. builtin cd ~ && ls
  6. fi
  7. }}

Comments

Permalink
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.

Maxim (Tue, 11/24/2009 - 20:01)

Add new comment

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