Mastering “CD Create”: Streamlining Your Terminal Workflow
If you spend any amount of time working in a command-line interface, you are undoubtedly familiar with the routine. You want to start a new project, feature branch, or scratch directory, so you type:
mkdir my-new-project
cd my-new-project
It is a minor ritual—a two-step dance that developers, system administrators, and power users perform thousands of times a year. But in the world of shell productivity, repetition is the enemy of efficiency.
Enter “cd create”: the developer philosophy and shorthand practice of combining directory creation and navigation into a single, seamless motion.
The Friction of the Two-Step Dance
Individually, both mkdir and cd are foundational commands.
mkdircreates a new directory.cdchanges your current working directory.
However, 99% of the time, when you create a directory, your immediate next action is to step inside it. Typing out the directory name twice—once to make it, and once to enter it—is redundant. While it only wastes a couple of seconds per execution, that friction compounds over time, breaking your flow state during heavy coding or file management sessions.
How to Implement Your Own “CD Create” Shortcut
Operating systems and shells (like Bash or Zsh) do not typically ship with a native cd-create command out of the box because cd is a shell builtin while mkdir is a standalone binary. Fortunately, customizing your shell takes just a few seconds.
1. The One-Liner Trick (No Configuration Required)
If you are on a remote server or don’t want to mess with configuration files, you can leverage a built-in shell parameter ($_$), which evaluates to the last argument of the previous command:
mkdir my-project && cd $_
The && ensures that the cd command only executes if mkdir succeeds, and $_ instantly passes your newly created directory name straight into the cd command.
2. The Permanent Shell Function (mkcd)
For a truly native experience, you can define a custom function inside your shell configuration file (such as ~/.bashrc, ~/.zshrc, or ~/.bash_profile).
Open your config file and add the following snippet:
mkcd() {
mkdir -p -- "$1" && cd -P -- "$1"
}
Why this implementation is robust:
mkdir -p: The-pflag allows you to create deeply nested directory structures on the fly (
Leave a Reply