The Power Combo: Bridging cd and Creation in the Terminal
If you spend any time working on the command line, your fingers instinctively know the rhythm of two commands: mkdir (to make a directory) and cd (to change into it).
Day in and day out, developers, system administrators, and power users repeat a ubiquitous workflow:
mkdir my-new-project
cd my-new-project
While harmless on the surface, typing out both commands every time you spin up a directory, branch, or component can feel like a microscopic tax on your productivity. Enter the concept of “cd create”—a shorthand philosophy implemented through shell functions, aliases, or custom scripts designed to merge creation and navigation into a single, seamless motion.
Why Standard Workflow Slows You Down
Individually, mkdir and cd are ancient, bulletproof staples of Unix-like operating systems. However, separating them introduces friction:
- Redundant Typing: You write the directory name twice—once to spawn it, and a second time to enter it.
- Context Switching: If a script or automated workflow fails halfway because a folder wasn’t created or entered properly, it breaks your flow state.
- Typo Risks: Long, nested project paths mean you risk misspelling the name on the second pass, resulting in a frustrating
No such file or directoryerror.
Building Your Own “Cd Create” Shortcut
Because cd is a shell builtin rather than a standalone binary executable, it changes the working directory of your current shell process. To combine creating and entering a directory seamlessly, you can leverage a simple shell function added to your .bashrc or .zshrc profile.
The Ultimate One-Liner Function
Add this neat snippet to your configuration file (~/.bashrc or ~/.zshrc):
mkcd() {
mkdir -p "$1" && cd "$1"
}
How It Works:
mkdir -p: The-pflag ensures that parent directories are created if they don’t exist yet, and crucially, it suppresses errors if the directory already exists.&&: This conditional operator ensures that thecdcommand executes only if the directory was successfully created or verified.$1: Passes your target directory name cleanly to both commands.
Once saved and sourced (source ~/.bashrc), you can replace your dual-command habit with a single stroke:
mkcd projects/2026/alpha-node
In one bound, you create the nested path and instantly land inside it, ready to run git init or npm init.
Alternative Patterns Across the Ecosystem
Different development environments have evolved their own versions of “cd create” utilities:
- Node/JavaScript Ecosystem (
degit/ package scaffolding): Tools likenpx degit user/repo my-folderautomatically pull templates and initialize folders in one go. - IDE Integrations: Modern terminals (like Warp, iTerm2, or VS Code integrated terminals) often feature smart path completion or plugin hooks that suggest creating a directory if it doesn’t already exist when targeted by a
cdcommand.
Conclusion
The command line is all about efficiency, muscle memory, and eliminating unnecessary keystrokes. By bridging the gap between mkdir and cd with a lightweight “cd create” function (mkcd), you remove a tiny friction point that you encounter dozens of times a week.
Next Step: Add
mkcdto your shell profile today, reclaim those extra seconds, and watch your terminal workflow glide smoother than ever.
Leave a Reply