Command for creating a directory and navigating into it directly?

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

[email protected]:~$ mdcd abc
[email protected]:~/abc$

Is this possible?

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

Add this to your .bashrc:

mdcd() {
    mkdir "[email protected]" && cd "[email protected]"

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

Solution 2

You could also simply do the following:

mkdir <name>; cd $_

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply