2

I often have to cd to a directory and ls to see the directory listing. Can it be done with one shot, so that I can add to .bashrc as alias. I searched on Google, there were some answers, but incomplete.

Kevdog777
  • 3,224
motiur
  • 153
  • Maybe I misunderstand the question, but can't you just (instead of cd dir; ls ) just do ls dir? – tink May 08 '13 at 06:10

1 Answers1

7

I assume that this means that you want to still be in the directory after ls has run, if not, just run ls with the dir as an argument.

cl() {
    cd "$@" && ls
}
foo$ mkdir bar
foo$ > bar/baz
foo$ > bar/qux
foo$ cl bar
baz  qux
bar$
Chris Down
  • 125,559
  • 25
  • 270
  • 266