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

+0

Liked the post? Why not show it?! Stroke Kyle's ego by stroking clicking his beard. You can click up to 50 times if you really liked it.


Spot a typo? Submit a PR with the fix! This entire blog is open sourced at https://github.com/kyleshevlin/blog
Newer Post: How to Set the Order of Media Queries for Sprockets Media Query Combiner
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.