Search code examples
macoszshaliaslscd

How to create alias in Mac Terminal?


Every time I type cd folder or cd .. I would like it to immediately run ls after.

Is there a way to do that?


Solution

  • Reposting the answer from another post

    Put this in .zshrc to create alias for cl:

    #print contents after moving to given directory
    cl()
    {
        cd $@
        ls
    }
    

    To override cd (not recommended), put this in .zshrc:

    #print contents after moving to given directory
    cd()
    {
        builtin cd $@
        ls
    }