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

Written by

in

Streamlining Your Terminal Workflow: The Power of “Cd Create”

Every developer knows the rhythmic, almost subconscious keystrokes of starting a new project in the terminal: you type mkdir my-awesome-project, hit enter, and immediately follow it up with cd my-awesome-project.

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


The Bottleneck of Separation

At first glance, executing two distinct commands (mkdir and cd) seems harmless. However, shells like Bash and Zsh treat them differently: mkdir is a standalone binary executable that creates a folder on your filesystem, while cd is a built-in shell command that changes your active working shell environment.

Because they live in separate realms, you cannot simply pipe them together. Typing mkdir project | cd project fails because each command runs in a separate subshell, leaving your actual terminal session stranded in the previous directory.

To bypass this, developers rely on clever shell functions and built-in shortcuts to achieve a true “cd create” workflow.


Implementing Your Own “CD Create” Shortcut

Fortunately, setting up a custom shortcut takes less than a minute. You can drop a tiny function into your shell configuration file (such as ~/.bashrc, ~/.zshrc, or your Fish config).

1. The Classic mkcd Function

Add the following snippet to your shell configuration file:

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

Why this works brilliantly:

  • 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 *