views:

25

answers:

3

Hi all,

I would like to create a new unix command to automatically list the contents of a directory after a CD command. So far, I've tried several things:

alias cdls='cd $1 | ls -l'

function cdls(){ cd $1; ls -l;}

Both perform the listing but dont change the working directory.

Thanks.

A: 

Maybe try:

alias cdls='cd $1 && ls -l'

Your examples are working for me, though (in zsh).

David
A: 

Use zsh. Google zsh {your distribution} for instructions.

fredley
I tried zsh on windows, it doesn't work. It successfully performs the listing but dont change the working directory.
gulbrandr
Tested again with the `function cdls()...`, and it worked! Thank you for the help.
gulbrandr
A: 

Why not just use cd dir/dir/ ; ls ?

Parker
because I don't want to type '; ls -l' after each cd.
gulbrandr
Hah, fair enough. Look into zsh in that case.
Parker