July 25, 2015

Bash Shortcut: How to Make Directory and Change Directory in One Command

If you're like me, you're constantly using the command line to make a directory and then immediately change to that directory. Here's a Bash function that will allows you to do that:

# Make a directory && cd into that directory
function mkdircd () { mkdir -p "$@" && eval cd "\"\$$#\""; }

This function takes the user supplied directory name, makes all the directories needed to get there, and then cds to that directory.

Hope you find it useful!

Categories
Web Development
Previous Post: Bash Shortcut: Copy your Present Working Directory to your Clipboard
Kyle Shevlin's face, which is mostly a beard with eyes
Kyle Shevlin is a front end web developer and software engineer who specializes in JavaScript and React.

If you enjoyed reading this blog post and want more, consider signing up for my newsletter. Subscribers get advanced updates on things like blog posts, courses, apps, podcasts and other material that I create. Think you might like it.

Sign Up Now