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.

  • Maybe I misunderstand the question, but can't you just (instead of cd dir; ls ) just do ls dir? – tink May 8 '13 at 6:10
6

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$
  • Where do I put the cl() function into , in the bashrc? – motiur May 8 '13 at 7:04
  • @MotiurRahman Yes, and then source your ~/.bashrc from ~/.bash_profile. – Chris Down May 8 '13 at 7:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.