Skip to content

Instantly share code, notes, and snippets.

@brock
Created March 27, 2015 01:37
Show Gist options
  • Save brock/5a8294382f1922b2bb21 to your computer and use it in GitHub Desktop.
Save brock/5a8294382f1922b2bb21 to your computer and use it in GitHub Desktop.
mcd needs to be a shell built-in function

mcd

I see this code used in so many README files and I always scratch my head...

mkdir myAppName
cd myAppName

This is perhaps the simplest possible function you can write in bash, and should be a built-in function:

mcd () {
	mkdir $1
	cd $1
}

So instead of the above, you simple type:

mcd myAppName

... and you have both created a directory and navigated into it.

All you have to do is add that function to your profile, which is one of the following:

  • ~/.bashrc
  • ~/.bash_profile
  • ~/.zshrc
  • ~/.zsh_profile
  • ~/.profile

Add that function to any of those files you have in your $HOME directory!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment