Quite often I need to perform this two commands:

mkdir abc
cd abc

I am curious whether there is a simple command (or an alias that I can create and use) to do it in one go, like

user@GROUP:~$ mdcd abc

Is this possible?

marked as duplicate by devnull, slm, Anthon, Ramesh, derobert May 5 '14 at 18:37

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Add this to your .bashrc:

mdcd() {
    mkdir "$@" && cd "$@"

Logout and login again or start a new shell to make the change.

  • 1
    Heh, exactly what I've been using for the past few years! No need to restart the shell though: just use source ~/.bashrc. – deltab May 5 '14 at 18:12
  • 1
    @deltab yes, but sourcing again can cause problem if some codes in .bashrc wasn't expected to be loaded twice. Just start a new shell is safer. – cuonglm May 31 '17 at 6:25

You could also simply do the following:

mkdir <name>; cd $_

Not the answer you're looking for? Browse other questions tagged or ask your own question.