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.
Asked
Active
Viewed 1,615 times
2
-
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 Answers
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
-
-
@MotiurRahman Yes, and then source your
~/.bashrc
from~/.bash_profile
. – Chris Down May 08 '13 at 07:27