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.
CAPTCHA
1 + 19 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.