How to Create a CD: Easy Step-by-Step Guide

Written by

in

Mastering “cd create”: Streamlining Your Terminal Workflow

Every day, developers, system administrators, and power users spend countless hours in the command line. For all its efficiency, the terminal is riddled with tiny, friction-filled habits. One of the most common micro-annoyances? Creating a new directory and immediately wanting to work inside it.

Traditionally, this requires a two-step ritual:

$ mkdir my-new-project
$ cd my-new-project

While typing those extra few characters takes only a second, the philosophy of efficiency dictates that repetition is meant to be automated. Enter “cd create”—the developer workflow practice of combining directory creation and navigation into a single, seamless motion.


Why the Two-Step Dance is Flawed

At first glance, typing mkdir followed by cd feels harmless. However, scaling this habit across dozens of directories, nested project structures, and quick-fire testing environments exposes hidden friction:

  • Redundancy and Typos: Typing the exact same directory name twice in a row opens the door for human error. A slip of the finger on the second line results in a frustrating no such file or directory error.
  • Context Switching: Conceptually, your intent is singular: “Take me into a new workspace called X.” Splitting this into two commands forces your brain to acknowledge two distinct steps for a single atomic goal.

Operating systems and shells (like Bash or Zsh) do not natively ship with a built-in cd-create command out of the box. This disconnect happens because cd is a built-in shell instruction, whereas mkdir is an independent binary executable. Fortunately, bridging this gap takes less than a minute.


Implementing Your Own “CD Create” Shortcut

You can easily bake this capability into your shell environment by defining a simple custom function.

1. The Classic mkcd Function

Open your terminal configuration file (such as ~/.bashrc, ~/.zshrc, or ~/.bash_aliases) in your favorite text editor and add the following snippet:

mkcd() {
  mkdir -p -- "$1" && cd -P -- "$1"
}

How it works under the hood:

  • mkdir -p: The -p flag ensures that if you specify a deeply nested path (

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *