Last Updated: February 25, 2016
·
821
· orangetux

Create and enter directory with one command

I often use these two command successively:

$ mkdir folder
$ cd folder

To combine these in one command (mde, make directory and enter) and make it constant, use the following command:

$ echo 'mde () { mkdir -p "$@" && cd "$@"; }' >> ~/.bashrc

Change .bashrc with the config file of the shell your use. To reload the config, use:

$ . ~/.bashrc

Now you can use it like:

$ mde folder

Note Some shells define their own aliases. E.g. defines md as an alias for mkdir -p. In order to check if the command already has been taken, use which <command>.