Often I run into a problem, I need to create a directory using mkdir and I have to cd into it. Some times I need to create a directory structure like this: ~/code/folder/sub_folder, the folder might be missing or the code might be missing. So I found the following shell command which will mkdir with padding and changes i.e cd to the created directory.

Paste the line below in your ~/.bashrc or ~/.zshrc:

function mkcd () { mkdir -p "$@" && eval cd "\"\$$#\""; }  Now source it as shown: $ source ~/.zshrc


Now the following command will create the directory structure and will change to it:

\$ mkcd ~/code/folder/sub_folder