Last Updated: February 25, 2016
·
411
· raddevon

Make and Change to a Directory in a Single Command

I've always been annoyed that I must create a directory and change into it using two commands. It seems the default behavior should change me into the directory I just made since I most likely want to work there. I wrote a really simple alias to do both in one shot:

function mcd() {
    mkdir "$@" && cd "$@"
}

Just drop this into your .bashrc or .zshrc and restart your shell. Now, you can mcd <dirname> to make a directory and change to it in one shot!