如何自动列出CD命令后的目录内容?

我想创build一个新的unix命令来自动列出CD命令后的目录内容。 到目前为止,我已经尝试了几件事情:

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

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

两者都执行列表,但不要更改工作目录。

谢谢。

使用zsh。 Google zsh {your distribution}获取说明。

 Do automatically an ls after every successfull cd: function cd { builtin cd "$@" && ls } Go up n levels: # Usage .. [n] function .. (){ local arg=${1:-1}; local dir="" while [ $arg -gt 0 ]; do dir="../$dir" arg=$(($arg - 1)); done cd $dir #>&/dev/null } 

也许尝试:

别名cdls ='cd $ 1 && ls -l'

你的例子正在为我工​​作,虽然(在ZSH)。

为什么不使用cd dir/dir/ ; ls cd dir/dir/ ; ls