4

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
user@GROUP:~/abc$

Is this possible?

shadyyx
  • 151

2 Answers2

12

Add this to your .bashrc:

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

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

cuonglm
  • 153,898
  • 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 05 '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 06:25
2

You could also simply do the following:

mkdir <name>; cd $_
Etheryte
  • 217