linux
BashLinux
mkcd: Make Directory and Enter It
A simple Bash function to create a directory and switch into it in a single command.
We’ve all been there: you create a new directory with mkdir and then immediately have to cd into it.
mkdir new-project
cd new-project
It’s a small friction, but it adds up. Here is a simple function to do both at once.
The Solution
Add this function to your .bashrc (or .zshrc):
# Create a folder (and subfolders) and enter it immediately
mkcd() {
mkdir -p "$1" && cd "$1"
}
How to Install
- Open your config file:
nano ~/.bashrc - Paste the code block above at the end of the file.
- Save and exit (
Ctrl+O,Enter,Ctrl+X). - Reload your configuration:
source ~/.bashrc
Usage
Now you can create deep directory structures and enter them instantly:
mkcd docker/docker-compose/vaultwarden
You will find yourself inside vaultwarden immediately.