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,194
  • 18
  • 43
  • 64
motiur
  • 153
  • 7
  • 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
  • 122,090
  • 24
  • 265
  • 262